-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
115 lines (73 loc) · 2.12 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 08 14:00:00 2016
@author: Leonardo Nascimento
"""
import sys
import image
from OpenGL.GL import *
from OpenGL.GLUT import *
from app import Application
WINDOW_SIZE = 1024, 768
def display():
glClearColor(0.2, 0.3, 0.7, 1.0)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
app.display(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT))
glutSwapBuffers()
def reshape(width, height):
glViewport(0, 0, width, height)
def keyboard(key, x, y):
if key == "s":
screenShot()
if key == "n":
app.next()
if key == "p":
app.previous()
if key == "f":
app.frustrum()
glutPostRedisplay()
def motion(x, y):
pass
def mouse(button, state, x, y):
pass
def screenShot():
width = glutGet(GLUT_WINDOW_WIDTH)
height = glutGet(GLUT_WINDOW_HEIGHT)
# rgba data size
size = width * height * 4
pixelBuffer = glGenBuffers(1)
glBindBuffer(GL_PIXEL_PACK_BUFFER, pixelBuffer)
glBufferData(GL_PIXEL_PACK_BUFFER, size, None, GL_STREAM_READ)
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, c_void_p(0))
data = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY)
image.write(width, height, data, size)
glUnmapBuffer(GL_PIXEL_PACK_BUFFER)
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0)
glDeleteBuffers(1, [pixelBuffer])
def initGLUT():
glutInit()
glutInitWindowSize(*WINDOW_SIZE)
glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH)
glutCreateWindow("DroneDeploy - Reconstruction Challenge")
glutDisplayFunc(display)
glutReshapeFunc(reshape)
glutKeyboardFunc(keyboard)
glutMotionFunc(motion)
glutMouseFunc(mouse)
def initOpenGL():
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
app = None
def initApplication():
if len(sys.argv) != 3:
raise Exception("Format: python <csvFile> <imagesLocation>")
global app
app = Application(sys.argv[1], sys.argv[2])
def main():
initGLUT()
initOpenGL()
initApplication()
return glutMainLoop()
if __name__ == "__main__":
main()