def gl_display(self): glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() gluOrtho2D( -self.h_pad, (self.frame_count) + self.h_pad, -self.v_pad, 1 + self.v_pad ) # ranging from 0 to cache_len-1 (horizontal) and 0 to 1 (vertical) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() if self.drag_mode: color1 = (0., .8, .5, .5) color2 = (0., .8, .5, 1.) else: color1 = (.25, .8, .8, .5) color2 = (.25, .8, .8, 1.) draw_gl_polyline([(0, 0), (self.current_frame_index, 0)], color=color1) draw_gl_polyline([(self.current_frame_index, 0), (self.frame_count, 0)], color=(.5, .5, .5, .5)) draw_gl_point((self.current_frame_index, 0), color=color1, size=40) draw_gl_point((self.current_frame_index, 0), color=color2, size=10) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix()
def gl_display(self): glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() width,height = glfwGetWindowSize(glfwGetCurrentContext()) h_pad = self.padding/width v_pad = self.padding/height gluOrtho2D(-h_pad, 1+h_pad, -v_pad, 1+v_pad) # gl coord convention glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() if self.drag_mode: color1 = (0.,.8,.5,.5) color2 = (0.,.8,.5,1.) else: color1 = (.25,.8,.8,.5) color2 = (.25,.8,.8,1.) draw_gl_polyline( [(0,0),(self.norm_seek_pos,0)],color=color1) draw_gl_polyline( [(self.norm_seek_pos,0),(1,0)],color=(.5,.5,.5,.5)) draw_gl_point((self.norm_seek_pos,0),color=color1,size=40) draw_gl_point((self.norm_seek_pos,0),color=color2,size=10) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix()
def gl_display(self): glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() gluOrtho2D(-self.h_pad, (self.frame_count)+self.h_pad, -self.v_pad, 1+self.v_pad) # ranging from 0 to cache_len-1 (horizontal) and 0 to 1 (vertical) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() if self.drag_mode: color1 = (0.,.8,.5,.5) color2 = (0.,.8,.5,1.) else: color1 = (.25,.8,.8,.5) color2 = (.25,.8,.8,1.) draw_gl_polyline( [(0,0),(self.current_frame_index,0)],color=color1) draw_gl_polyline( [(self.current_frame_index,0),(self.frame_count,0)],color=(.5,.5,.5,.5)) draw_gl_point((self.current_frame_index,0),color=color1,size=40) draw_gl_point((self.current_frame_index,0),color=color2,size=10) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix()
def gl_display(self): glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() width, height = glfwGetWindowSize(glfwGetCurrentContext()) h_pad = self.padding / width v_pad = self.padding / height gluOrtho2D(-h_pad, 1 + h_pad, -v_pad, 1 + v_pad) # gl coord convention glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() if self.drag_mode: color1 = (0., .8, .5, .5) color2 = (0., .8, .5, 1.) else: color1 = (.25, .8, .8, .5) color2 = (.25, .8, .8, 1.) draw_gl_polyline([(0, 0), (self.norm_seek_pos, 0)], color=color1) draw_gl_polyline([(self.norm_seek_pos, 0), (1, 0)], color=(.5, .5, .5, .5)) draw_gl_point((self.norm_seek_pos, 0), color=color1, size=40) draw_gl_point((self.norm_seek_pos, 0), color=color2, size=10) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix()
def gl_display(self): glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() gluOrtho2D( -self.h_pad, (self.frame_count) + self.h_pad, -self.v_pad, 1 + self.v_pad ) # ranging from 0 to cache_len-1 (horizontal) and 0 to 1 (vertical) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() color1 = (.1, .9, .2, .5) color2 = (.1, .9, .2, .5) if self.in_mark != 0 or self.out_mark != self.frame_count: draw_gl_polyline([(self.in_mark, 0), (self.out_mark, 0)], color=(.1, .9, .2, .5), thickness=2) draw_gl_point((self.in_mark, 0), color=color2, size=10) draw_gl_point((self.out_mark, 0), color=color2, size=10) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix()
def gl_display_in_window(self): active_window = glfwGetCurrentContext() glfwMakeContextCurrent(self._window) clear_gl_screen() # Set Matrix unsing gluOrtho2D to include padding for the marker of radius r # ############################ # r # # 0,0##################w,h # # # # # # # # # #r# #r# # # # # # # # # # 0,h##################w,h # # r # ############################ r = 60 gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() p_window_size = glfwGetWindowSize(self._window) # compensate for radius of marker gluOrtho2D( -r, p_window_size[0] + r, p_window_size[1] + r, -r) # origin in the top left corner just like the img np-array # Switch back to Model View Matrix gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() screen_pos = denormalize(self.display_pos, p_window_size, flip_y=True) draw_marker(screen_pos) #some feedback on the detection state if self.detected and self.on_position: draw_gl_point(screen_pos, 5, (0., 1., 0., 1.)) else: draw_gl_point(screen_pos, 5, (1., 0., 0., 1.)) glfwSwapBuffers(self._window) glfwMakeContextCurrent(active_window)
def gl_display_in_window(self): active_window = glfwGetCurrentContext() glfwMakeContextCurrent(self._window) clear_gl_screen() # Set Matrix unsing gluOrtho2D to include padding for the marker of radius r # ############################ # r # # 0,0##################w,h # # # # # # # # # #r# #r# # # # # # # # # # 0,h##################w,h # # r # ############################ r = 60 gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() p_window_size = glfwGetWindowSize(self._window) # compensate for radius of marker gluOrtho2D(-r,p_window_size[0]+r,p_window_size[1]+r, -r) # origin in the top left corner just like the img np-array # Switch back to Model View Matrix gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() screen_pos = denormalize(self.display_pos,p_window_size,flip_y=True) draw_marker(screen_pos) #some feedback on the detection state if self.detected and self.on_position: draw_gl_point(screen_pos, 5, (0.,1.,0.,1.)) else: draw_gl_point(screen_pos, 5, (1.,0.,0.,1.)) glfwSwapBuffers(self._window) glfwMakeContextCurrent(active_window)
def gl_display(self): glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() gluOrtho2D(-self.h_pad, (self.frame_count)+self.h_pad, -self.v_pad, 1+self.v_pad) # ranging from 0 to cache_len-1 (horizontal) and 0 to 1 (vertical) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() #Draw............................................................................... for pos_to_draw in self.pos_begin_trial: draw_gl_point((pos_to_draw, 0), size = 5, color = (.5, .5, .5, .5)) draw_gl_polyline( [(pos_to_draw,.05),(pos_to_draw,0)], color = (.5, .5, .5, .5)) for pos_to_draw in self.pos_first_response: draw_gl_point((pos_to_draw, 0), size = 5, color = (.0, .0, .5, 1.)) draw_gl_polyline( [(pos_to_draw,.025),(pos_to_draw,0)], color = (.0, .0, .7, 1.)) for pos_to_draw in self.pos_end_limited_hold: draw_gl_point((pos_to_draw, 0), size = 5, color = (.5, .0, .0, 1.)) draw_gl_polyline( [(pos_to_draw,.025),(pos_to_draw,0)], color = (.7, .0, .0, 1.)) for x, first_response in enumerate(self.pos_first_response): draw_gl_polyline( [(self.pos_end_limited_hold[x],.025),(first_response,.025)], color = (1., .5, .0, 1.)) #Draw............................................................................... glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix()
def gl_display(self): glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() gluOrtho2D(-self.h_pad, (self.frame_count)+self.h_pad, -self.v_pad, 1+self.v_pad) # ranging from 0 to cache_len-1 (horizontal) and 0 to 1 (vertical) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() color1 = (.1,.9,.2,.5) color2 = (.1,.9,.2,.5) if self.in_mark != 0 or self.out_mark != self.frame_count: draw_gl_polyline( [(self.in_mark,0),(self.out_mark,0)],color=(.1,.9,.2,.5),thickness=2) draw_gl_point((self.in_mark,0),color=color2,size=10) draw_gl_point((self.out_mark,0),color=color2,size=10) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix()
def player(g_pool,size): """player - Shows 9 point calibration pattern - Plays a source video synchronized with world process - Get src videos from directory (glob) - Iterate through videos on each record event """ grid = make_grid() grid *=2.5###scale to fit # player object player = Temp() player.play_list = glob('src_video/*') path_parent = os.path.dirname( os.path.abspath(sys.argv[0])) player.playlist = [os.path.join(path_parent, path) for path in player.play_list] player.captures = [autoCreateCapture(src) for src in player.playlist] print "Player found %i videos in src_video"%len(player.captures) player.captures = [c for c in player.captures if c is not None] print "Player sucessfully loaded %i videos in src_video"%len(player.captures) # for c in player.captures: c.auto_rewind = False player.current_video = 0 # Callbacks def on_resize(w, h): adjust_gl_view(w,h) def on_key(key, pressed): if key == GLFW_KEY_ESC: on_close() def on_char(char, pressed): if pressed: g_pool.player_input.value = char def on_close(): g_pool.quit.value = True print "Player Process closing from window" def draw_circle(pos,r,c): pts = cv2.ellipse2Poly(tuple(pos),(r,r),0,0,360,10) draw_gl_polyline(pts,c,'Polygon') def draw_marker(pos): pos = int(pos[0]),int(pos[1]) black = (0.,0.,0.,1.) white = (1.,1.,1.,1.) for r,c in zip((50,40,30,20,10),(black,white,black,white,black)): draw_circle(pos,r,c) # Initialize glfw glfwInit() glfwOpenWindow(size[0], size[1], 0, 0, 0, 8, 0, 0, GLFW_WINDOW) glfwSetWindowTitle("Player") glfwSetWindowPos(100,0) glfwDisable(GLFW_AUTO_POLL_EVENTS) # Callbacks glfwSetWindowSizeCallback(on_resize) glfwSetWindowCloseCallback(on_close) glfwSetKeyCallback(on_key) glfwSetCharCallback(on_char) # gl state settings gl.glEnable(gl.GL_POINT_SMOOTH) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_BLEND) gl.glDisable (gl.GL_DEPTH_TEST) gl.glClearColor(1.,1.,1.,0.) while glfwGetWindowParam(GLFW_OPENED) and not g_pool.quit.value: glfwPollEvents() if g_pool.player_refresh.wait(0.01): g_pool.player_refresh.clear() clear_gl_screen() if g_pool.marker_state.value !=0: # Set Matrix unsing gluOrtho2D to include padding for the marker of radius r # ############################ # r # # 0,0##################w,h # # # # # # # # # #r# #r# # # # # # # # # # 0,h##################w,h # # r # ############################ r = 60 gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() # compensate for radius of marker gluOrtho2D(-r,glfwGetWindowSize()[0]+r,glfwGetWindowSize()[1]+r, -r) # origin in the top left corner just like the img np-array # Switch back to Model View Matrix gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() screen_pos = denormalize(g_pool.marker[:],glfwGetWindowSize(),flip_y=True) #some feedback on the detection state draw_marker(screen_pos) if g_pool.ref[:] == [0.,0.]: # world ref is detected draw_gl_point(screen_pos, 5.0, (1.,0.,0.,1.)) else: draw_gl_point(screen_pos, 5.0, (0.,1.,0.,1.)) elif g_pool.play.value: if len(player.captures): frame = player.captures[player.current_video].get_frame() img = frame.img if img: draw_gl_texture(img) else: player.captures[player.current_video].rewind() player.current_video +=1 if player.current_video >= len(player.captures): player.current_video = 0 g_pool.play.value = False else: print 'PLAYER: Warning: No Videos available to play. Please put your vidoes into a folder called "src_video" in the Capture folder.' g_pool.play.value = False glfwSwapBuffers() glfwCloseWindow() glfwTerminate() print "PLAYER Process closed"
def display(self,img): for kp in self.canditate_points: draw_gl_point((kp.pt[0]*2,kp.pt[1]*2),size=int(kp.size)*4,color=(0.,1.,1.,.5))