Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set_detector(new_detector):
g_pool.pupil_detector.cleanup()
g_pool.pupil_detector = new_detector(g_pool)
g_pool.pupil_detector.init_gui(g_pool.sidebar)
# Initialize glfw
glfw.glfwInit()
title = "eye %s"%eye_id
width,height = session_settings.get('window_size',cap.frame_size)
main_window = glfw.glfwCreateWindow(width,height, title, None, None)
window_pos = session_settings.get('window_position',window_position_default)
glfw.glfwSetWindowPos(main_window,window_pos[0],window_pos[1])
glfw.glfwMakeContextCurrent(main_window)
cygl.utils.init()
# gl_state settings
basic_gl_setup()
g_pool.image_tex = Named_Texture()
glfw.glfwSwapInterval(0)
#setup GUI
g_pool.gui = ui.UI()
g_pool.gui.scale = session_settings.get('gui_scale',1)
g_pool.sidebar = ui.Scrolling_Menu("Settings",pos=(-300,0),size=(0,0),header_pos='left')
general_settings = ui.Growing_Menu('General')
general_settings.append(ui.Slider('scale',g_pool.gui, setter=set_scale,step = .05,min=1.,max=2.5,label='Interface Size'))
general_settings.append(ui.Button('Reset window size',lambda: glfw.glfwSetWindowSize(main_window,frame.width,frame.height)) )
general_settings.append(ui.Switch('flip',g_pool,label='Flip image display'))
general_settings.append(ui.Selector('display_mode',g_pool,setter=set_display_mode_info,selection=['camera_image','roi','algorithm'], labels=['Camera Image', 'ROI', 'Algorithm'], label="Mode") )
def _main():
# These Window hints are used to specify
# which opengl version to use and other details
# for the opengl context that will be created
glfw.glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, GL_VERSION[0])
glfw.glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, GL_VERSION[1])
glfw.glfwWindowHint(GLFW_OPENGL_PROFILE,
GLFW_OPENGL_CORE_PROFILE)
glfw.glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, True)
window = glfw.glfwCreateWindow(
1024, 1024, "Trying this crap".encode('utf-8'), None, None)
if not window:
raise SystemExit("glfwCreateWindow failed")
glfw.glfwMakeContextCurrent(window)
glewInit()
glfw.glfwSwapInterval(1)
# If everything went well the following calls
# will display the version of opengl being used
print('Vendor: %s' % (gl_get_unicode(GL_VENDOR)))
print('Opengl version: %s' % (gl_get_unicode(GL_VERSION_C)))
print('GLSL Version: %s' % (gl_get_unicode(GL_SHADING_LANGUAGE_VERSION)))
print('Renderer: %s' % (gl_get_unicode(GL_RENDERER)))
r = Renderer(1024, 1024)
glfw.glfwSetFramebufferSizeCallback(window, r.on_resize)
try:
glClearColor(0.5, 0.5, 0.5, 0)
while not glfw.glfwWindowShouldClose(window):
glClear(GL_COLOR_BUFFER_BIT)
):
self.mouse_drag = False
if self.depth_window is None:
self.pitch = 0
self.yaw = 0
win_size = glfw.glfwGetWindowSize(self.g_pool.main_window)
self.depth_window = glfw.glfwCreateWindow(
win_size[0], win_size[1], "3D Point Cloud"
)
glfw.glfwSetMouseButtonCallback(
self.depth_window, on_depth_mouse_button
)
active_window = glfw.glfwGetCurrentContext()
glfw.glfwMakeContextCurrent(self.depth_window)
gl_utils.basic_gl_setup()
gl_utils.make_coord_system_norm_based()
# refresh speed settings
glfw.glfwSwapInterval(0)
glfw.glfwMakeContextCurrent(active_window)
gl.glPushMatrix()
# apply trans_mat to our quad - this will stretch the quad such that the
# surface will span the window extends
gl.glLoadMatrixf(trans_mat)
world_tex.draw()
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glPopMatrix()
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glPopMatrix()
self.draw_recent_pupil_positions()
glfw.glfwSwapBuffers(self._window)
glfw.glfwMakeContextCurrent(active_window)
def _gl_state_settings(window):
active_window = glfw.glfwGetCurrentContext()
glfw.glfwMakeContextCurrent(window)
gl_utils.basic_gl_setup()
gl_utils.make_coord_system_norm_based()
glfw.glfwSwapInterval(0)
glfw.glfwMakeContextCurrent(active_window)
except ZeroDivisionError:
pass
if g_pool.writer:
g_pool.writer.write_video_frame(frame)
result = event.get("pupil_detection_result", None)
if result is not None:
pupil_socket.send(result)
cpu_graph.update()
# GL drawing
if window_should_update():
if is_window_visible(main_window):
glfw.glfwMakeContextCurrent(main_window)
clear_gl_screen()
glViewport(0, 0, *camera_render_size)
for p in g_pool.plugins:
p.gl_display()
glViewport(0, 0, *camera_render_size)
# render the ROI
g_pool.u_r.draw(g_pool.gui.scale)
if g_pool.display_mode == "roi":
g_pool.u_r.draw_points(g_pool.gui.scale)
glViewport(0, 0, *window_size)
# render graphs
fps_graph.draw()
cpu_graph.draw()
def gl_display_in_window(self, world_tex):
"""
here we map a selected surface onto a separate window.
"""
if self._window and self.surface.detected:
active_window = glfw.glfwGetCurrentContext()
glfw.glfwMakeContextCurrent(self._window)
gl_utils.clear_gl_screen()
# cv uses 3x3 gl uses 4x4 transformation matrices
width, height = self.tracker.camera_model.resolution
img_corners = np.array(
[(0, height), (width, height), (width, 0), (0, 0)], dtype=np.float32
)
denorm_trans = _get_norm_to_points_trans(img_corners)
trans_mat = self.surface.dist_img_to_surf_trans @ denorm_trans
trans_mat = gl_utils.cvmat_to_glmat(trans_mat)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glPushMatrix()
gl.glLoadIdentity()
gl.glOrtho(0, 1, 0, 1, -1, 1)
def on_resize(window, w, h):
if is_window_visible(window):
active_window = glfw.glfwGetCurrentContext()
glfw.glfwMakeContextCurrent(window)
hdpi_factor = float(glfw.glfwGetFramebufferSize(window)[0] / glfw.glfwGetWindowSize(window)[0])
g_pool.gui.scale = g_pool.gui_user_scale * hdpi_factor
g_pool.gui.update_window(w, h)
g_pool.gui.collect_menus()
for g in g_pool.graphs:
g.scale = hdpi_factor
g.adjust_window_size(w, h)
adjust_gl_view(w, h)
glfw.glfwMakeContextCurrent(active_window)
def _gl_state_settings(window):
active_window = glfw.glfwGetCurrentContext()
glfw.glfwMakeContextCurrent(window)
gl_utils.basic_gl_setup()
gl_utils.make_coord_system_norm_based()
glfw.glfwSwapInterval(0)
glfw.glfwMakeContextCurrent(active_window)
os.chdir(cwd)
# version hints
glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MAJOR, 3)
glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MINOR, 3)
glfw.glfwWindowHint(glfw.GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE)
glfw.glfwWindowHint(glfw.GLFW_OPENGL_PROFILE,
glfw.GLFW_OPENGL_CORE_PROFILE)
# make a window
self.width, self.height = 640, 480
self.aspect = self.width/float(self.height)
self.win = glfw.glfwCreateWindow(self.width, self.height,
b"Particle System")
# make context current
glfw.glfwMakeContextCurrent(self.win)
# initialize GL
glViewport(0, 0, self.width, self.height)
glEnable(GL_DEPTH_TEST)
glClearColor(0.2, 0.2, 0.2,1.0)
# set window callbacks
glfw.glfwSetMouseButtonCallback(self.win, self.onMouseButton)
glfw.glfwSetKeyCallback(self.win, self.onKeyboard)
glfw.glfwSetWindowSizeCallback(self.win, self.onSize)
# create 3D
self.psys = ParticleSystem(self.numP)
self.box = Box(1.0)
# exit flag