def gl_display_in_window(self,world_tex_id): """ here we map a selected surface onto a seperate window. """ if self._window and self.detected: active_window = glfwGetCurrentContext() glfwMakeContextCurrent(self._window) clear_gl_screen() # cv uses 3x3 gl uses 4x4 tranformation matricies m = cvmat_to_glmat(self.m_from_screen) glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho(0, 1, 0, 1,-1,1) # gl coord convention glMatrixMode(GL_MODELVIEW) glPushMatrix() #apply m to our quad - this will stretch the quad such that the ref suface will span the window extends glLoadMatrixf(m) draw_named_texture(world_tex_id) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix() # now lets get recent pupil positions on this surface: draw_points_norm(self.gaze_on_srf,color=RGBA(0.,8.,.5,.8), size=80) glfwSwapBuffers(self._window) glfwMakeContextCurrent(active_window) if self.window_should_close: self.close_window()
def gl_draw_corners(self): """ draw surface and markers """ if self.detected: frame = cv2.perspectiveTransform(marker_corners_norm.reshape(-1,1,2),self.m_to_screen) draw_points_norm(frame.reshape((4,2)),20,RGBA(1.0,0.2,0.6,.5))
def gl_display(self): """ use gl calls to render at least: the published position of the reference better: show the detected postion even if not published """ if self.active: if self.pos is not None: draw_points_norm([self.pos], size=15, color=RGBA(0.1, 0.8, 0.9, 1.0)) p = self.fingertip['norm_rect_points'] draw_polyline_norm([p[0], p[1], p[2], p[3], p[0]], color=RGBA(0.1, 0.8, 0.9, 0.3), thickness=3) if self.mode == 'calibration' and self.fingertip_tracker.train_done in ( 0, 1): for p in self.fingertip_tracker.ROIpts: points = [(x, 1 - y) for x in [p[1], p[1] + p[3]] for y in [p[0], p[0] + p[2]]] draw_polyline_norm( [points[0], points[1], points[3], points[2]], color=RGBA(0.1, 0.9, 0.7, 1.0), line_type=GL_POLYGON)
def gl_display(self): super(Accuracy_Test, self).gl_display() if not self.active and self.error_lines is not None: draw_polyline_norm(self.error_lines,color=RGBA(1.,0.5,0.,.5),line_type=gl.GL_LINES) draw_points_norm(self.error_lines[1::2],color=RGBA(.0,0.5,0.5,.5),size=3) draw_points_norm(self.error_lines[0::2],color=RGBA(.5,0.0,0.0,.5),size=3)
def gl_display(self): for pt,a in self.pupil_display_list: #print('display recent:', pt, a) #This could be faster if there would be a method to also add multiple colors per point draw_points_norm([pt], size=100, color=RGBA(1.,.2,.4,a))
def gl_display(self): """ use gl calls to render at least: the published position of the reference better: show the detected postion even if not published """ if self.active: draw_points_norm([self.smooth_pos], size=15, color=RGBA(1., 1., 0., .5)) if self.active and self.detected: for e in self.candidate_ellipses: pts = cv2.ellipse2Poly((int(e[0][0]), int(e[0][1])), (int(e[1][0] / 2), int(e[1][1] / 2)), int(e[-1]), 0, 360, 15) draw_polyline(pts, color=RGBA(0., 1., 0, 1.)) # lets draw an indicator on the autostop count e = self.candidate_ellipses[3] pts = cv2.ellipse2Poly((int(e[0][0]), int(e[0][1])), (int(e[1][0] / 2), int(e[1][1] / 2)), int(e[-1]), 0, 360, 360 / self.auto_stop_max) indicator = [e[0]] + pts[self.auto_stop:].tolist() + [e[0]] draw_polyline(indicator, color=RGBA(8., 0.1, 0.1, .8), line_type=GL_POLYGON) else: pass
def gl_display(self): """ use gl calls to render at least: the published position of the reference better: show the detected postion even if not published """ if self.active: draw_points_norm([self.smooth_pos],size=15,color=RGBA(1.,1.,0.,.5)) if self.active and self.detected: for e in self.candidate_ellipses: pts = cv2.ellipse2Poly( (int(e[0][0]),int(e[0][1])), (int(e[1][0]/2),int(e[1][1]/2)), int(e[-1]),0,360,15) draw_polyline(pts,color=RGBA(0.,1.,0,1.)) # lets draw an indicator on the autostop count e = self.candidate_ellipses[3] pts = cv2.ellipse2Poly( (int(e[0][0]),int(e[0][1])), (int(e[1][0]/2),int(e[1][1]/2)), int(e[-1]),0,360,360/self.auto_stop_max) indicator = [e[0]] + pts[self.auto_stop:].tolist() + [e[0]] draw_polyline(indicator,color=RGBA(8.,0.1,0.1,.8),line_type=GL_POLYGON) else: pass
def gl_display_in_window(self,world_tex): """ here we map a selected surface onto a seperate window. """ if self._window and self.detected: active_window = glfwGetCurrentContext() glfwMakeContextCurrent(self._window) clear_gl_screen() # cv uses 3x3 gl uses 4x4 tranformation matricies m = cvmat_to_glmat(self.m_from_screen) glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho(0, 1, 0, 1,-1,1) # gl coord convention glMatrixMode(GL_MODELVIEW) glPushMatrix() #apply m to our quad - this will stretch the quad such that the ref suface will span the window extends glLoadMatrixf(m) world_tex.draw() glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix() # now lets get recent pupil positions on this surface: for gp in self.gaze_on_srf: draw_points_norm([gp['norm_pos']],color=RGBA(0.0,0.8,0.5,0.8), size=80) glfwSwapBuffers(self._window) glfwMakeContextCurrent(active_window)
def recent_events(self, events): frame = events.get('frame') if not frame: return if self.fill: thickness = -1 else: thickness = self.thickness for pt in events.get('gaze_positions', []): self.pupil_display_list.append( (pt['norm_pos'], pt['confidence'] * 0.8)) self.pupil_display_list[:-3] = [] # pts = [denormalize(pt['norm_pos'],frame.img.shape[:-1][::-1],flip_y=True) for pt in events.get('gaze_positions',[]) if pt['confidence']>=self.min_confidence] for pt, a in self.pupil_display_list: #print('vis_circle', pt, a) transparent_circle(frame.img, pt, radius=self.radius, color=(self.b, self.g, self.r, self.a), thickness=thickness) draw_points_norm([pt], size=self.radius, color=RGBA(self.r, self.g, self.b, self.a))
def gl_draw_frame(self,img_size): """ draw surface and markers """ if self.detected: frame = np.array([[[0,0],[1,0],[1,1],[0,1],[0,0]]],dtype=np.float32) hat = np.array([[[.3,.7],[.7,.7],[.5,.9],[.3,.7]]],dtype=np.float32) hat = cv2.perspectiveTransform(hat,self.m_to_screen) frame = cv2.perspectiveTransform(frame,self.m_to_screen) alpha = min(1,self.build_up_status/self.required_build_up) draw_polyline_norm(frame.reshape((5,2)),1,RGBA(1.0,0.2,0.6,alpha)) draw_polyline_norm(hat.reshape((4,2)),1,RGBA(1.0,0.2,0.6,alpha)) #grid = frame.reshape((5,2)) # self.crop_region = np.array([ # [grid[0][0] * img_size[1], grid[0][1] * img_size[0]], # [grid[1][0] * img_size[1], grid[1][1] * img_size[0]], # [grid[2][0] * img_size[1], grid[2][1] * img_size[0]], # [grid[3][0] * img_size[1], grid[3][1] * img_size[0]]], # dtype=np.float32) draw_points_norm(frame.reshape((5,-1))[0:1]) text_anchor = frame.reshape((5,-1))[2] text_anchor[1] = 1-text_anchor[1] text_anchor *=img_size[1],img_size[0] self.glfont.draw_text(text_anchor[0],text_anchor[1],self.marker_status())
def gl_display(self): feature = self.__previously_detected_feature if feature: draw_points_norm( [feature["norm_pos"]], size=self._RADIUS_OF_CIRCLE_DISPLAYED, color=RGBA(0.0, 1.0, 0.0, 0.5), )
def gl_draw_corners(self): """ draw surface and markers """ if self.detected: frame = np.array([[[0,0],[1,0],[1,1],[0,1]]],dtype=np.float32) frame = cv2.perspectiveTransform(frame,self.m_to_screen) draw_points_norm(frame.reshape((4,2)),15,RGBA(1.0,0.2,0.6,.5))
def gl_display(self): """ use gl calls to render at least: the published position of the reference better: show the detected postion even if not published """ # Draw rectangle preview with threshold color if self.world_size: offset = self.world_size[0] / 130.0 ratio = self.world_size[1] / self.world_size[0] rect_size = None if ratio == 0.75: rect_size = [(self.world_size[0] / 20.0), self.world_size[0] / 20.0 * 1.3] else: rect_size = [(self.world_size[0] / 20.0), self.world_size[0] / 20.0 * 1.0] rect_color = colorsys.hsv_to_rgb(self.color_h / 360, self.color_s / 100, self.color_v / 100) draw_rounded_rect( [offset, self.world_size[1] - rect_size[1] - offset], size=rect_size, corner_radius=offset / 2, color=RGBA(rect_color[0], rect_color[1], rect_color[2], 1.)) if self.active: # Draw contour of hand if self.show_contour: con = [(c[0][0], c[0][1]) for c in self.contour] if len(con) > 2: con.append(con[0]) draw_polyline(con, color=RGBA(0., 1., 0., .7), thickness=5.0) # Draw all detected fingertips if len(self.markers) == 1: marker_norm = normalize( self.markers[0], (self.world_size[0], self.world_size[1]), flip_y=True) draw_points_norm([marker_norm], size=30, color=RGBA(0., 1., 1., .5)) else: for mark in self.markers: marker_norm = normalize( mark, (self.world_size[0], self.world_size[1]), flip_y=True) draw_points_norm([marker_norm], size=30, color=RGBA(0., 0., 1., .5))
def gl_display(self): """ use gl calls to render at least: the published position of the reference better: show the detected postion even if not published """ if self.active: draw_points_norm([self.smooth_pos], size=15, color=RGBA(1., 1., 0., .5)) if self.active and len(self.markers): # draw the largest ellipse of all detected markers for marker in self.markers: e = marker['ellipses'][-1] pts = cv2.ellipse2Poly((int(e[0][0]), int(e[0][1])), (int(e[1][0] / 2), int(e[1][1] / 2)), int(e[-1]), 0, 360, 15) draw_polyline(pts, color=RGBA(0., 1., 0, 1.)) if len(self.markers) > 1: draw_polyline(pts, 1, RGBA(1., 0., 0., .5), line_type=GL_POLYGON) # draw indicator on the first detected marker if self.counter and self.markers[0]['marker_type'] == 'Ref': e = self.markers[0]['ellipses'][-1] pts = cv2.ellipse2Poly((int(e[0][0]), int(e[0][1])), (int(e[1][0] / 2), int(e[1][1] / 2)), int(e[-1]), 0, 360, 360 // self.counter_max) indicator = [e[0]] + pts[self.counter:].tolist()[::-1] + [e[0]] draw_polyline(indicator, color=RGBA(0.1, .5, .7, .8), line_type=GL_POLYGON) # draw indicator on the stop marker(s) if self.auto_stop: for marker in self.markers: if marker['marker_type'] == 'Stop': e = marker['ellipses'][-1] pts = cv2.ellipse2Poly( (int(e[0][0]), int(e[0][1])), (int(e[1][0] / 2), int(e[1][1] / 2)), int(e[-1]), 0, 360, 360 // self.auto_stop_max) indicator = [e[0]] + pts[self.auto_stop:].tolist() + [ e[0] ] draw_polyline(indicator, color=RGBA(8., 0.1, 0.1, .8), line_type=GL_POLYGON) else: pass
def gl_display(self): if self.visualize and self.error_lines is not None: draw_polyline_norm(self.error_lines, color=RGBA(1., 0.5, 0., .5), line_type=gl.GL_LINES) draw_points_norm(self.error_lines[1::2], color=RGBA(.0, 0.5, 0.5, .5), size=3) draw_points_norm(self.error_lines[0::2], color=RGBA(.5, 0.0, 0.0, .5), size=3)
def gl_display(self): for pt, a, gaze_pup in self.pupil_display_list: #This could be faster if there would be a method to also add multiple colors per point color = None if gaze_pup[0] and gaze_pup[1]: color = RGBA(0, 1., 0, a) elif gaze_pup[0] and not gaze_pup[1]: color = RGBA(1., 1., 0, a) elif not gaze_pup[0] and gaze_pup[1]: color = RGBA(1., 1., 1., a) else: color = RGBA(1., 0, 0, a) draw_points_norm([pt], size=35, color=color)
def gl_display(self): global emotion_col print emotion_key if (emotion_key=='115'): emotion_col=RGBA(0,0,255,.4) elif (emotion_key=='104'): emotion_col=RGBA(1,.5,.2,.4) elif (emotion_key=='97'): emotion_col=RGBA(1.,.1,.1,.4) elif (emotion_key=='110'): emotion_col=RGBA(255,255,255,0) else: emotion_col=RGBA(255,255,255,0) draw_points_norm(self.pupil_display_list,color=emotion_col)
def gl_display(self): if self.vis_mapping_error and self.error_lines is not None: draw_polyline_norm(self.error_lines, color=RGBA(1., 0.5, 0., .5), line_type=gl.GL_LINES) draw_points_norm(self.error_lines[1::2], size=3, color=RGBA(.0, 0.5, 0.5, .5)) draw_points_norm(self.error_lines[0::2], size=3, color=RGBA(.5, 0.0, 0.0, .5)) if self.vis_calibration_area and self.calibration_area is not None: draw_polyline_norm(self.calibration_area, thickness=2., color=RGBA(.663, .863, .463, .8), line_type=gl.GL_LINE_LOOP)
def gl_draw_frame(self,img_size): """ draw surface and markers """ if self.detected: frame = np.array([[[0,0],[1,0],[1,1],[0,1],[0,0]]],dtype=np.float32) hat = np.array([[[.3,.7],[.7,.7],[.5,.9],[.3,.7]]],dtype=np.float32) hat = cv2.perspectiveTransform(hat,self.m_to_screen) frame = cv2.perspectiveTransform(frame,self.m_to_screen) alpha = min(1,self.build_up_status/self.required_build_up) draw_polyline_norm(frame.reshape((5,2)),1,RGBA(1.0,0.2,0.6,alpha)) draw_polyline_norm(hat.reshape((4,2)),1,RGBA(1.0,0.2,0.6,alpha)) draw_points_norm(frame.reshape((5,-1))[0:1]) text_anchor = frame.reshape((5,-1))[2] text_anchor[1] = 1-text_anchor[1] text_anchor *=img_size[1],img_size[0] self.glfont.draw_text(text_anchor[0],text_anchor[1],self.marker_status())
def gl_display(self): if self.vis_mapping_error and self.error_lines is not None: draw_polyline_norm( self.error_lines, color=RGBA(1.0, 0.5, 0.0, 0.5), line_type=gl.GL_LINES ) draw_points_norm( self.error_lines[1::2], size=3, color=RGBA(0.0, 0.5, 0.5, 0.5) ) draw_points_norm( self.error_lines[0::2], size=3, color=RGBA(0.5, 0.0, 0.0, 0.5) ) if self.vis_calibration_area and self.calibration_area is not None: draw_polyline_norm( self.calibration_area, thickness=2.0, color=RGBA(0.663, 0.863, 0.463, 0.8), line_type=gl.GL_LINE_LOOP, )
def gl_display(self): """ use gl calls to render at least: the published position of the reference better: show the detected postion even if not published """ if self.active and self.detected: draw_points_norm([self.smooth_pos],size=15,color=RGBA(1.,1.,0.,.5)) for e in self.candidate_ellipses: pts = cv2.ellipse2Poly( (int(e[0][0]),int(e[0][1])), (int(e[1][0]/2),int(e[1][1]/2)), int(e[-1]),0,360,15) draw_polyline(pts,color=RGBA(0.,1.,0,1.)) else: pass
def gl_display(self): # blink? if int(self.blink_counter / 10) % 2 == 1: if self.currently_recording.is_set(): draw_points_norm([(0.01, 0.1)], size=35, color=RGBA(0.1, 1.0, 0.1, 0.8)) if self.currently_saving.is_set(): draw_points_norm([(0.01, 0.01)], size=35, color=RGBA(1.0, 0.1, 0.1, 0.8)) self.blink_counter += 1 if (self.preview_ximea): if (self.currently_recording.is_set()): #if we are currently saving, don't grab images im = np.ones((*self.imshape, 3)).astype(np.uint8) alp = 0 elif (not self.camera_open): logger.info(f'Unable to Open Camera!') self.preview_ximea = False im = np.zeros((*self.imshape, 3)).astype(np.uint8) alp = 0.5 else: im = ximea_utils.decode_ximea_frame(self.camera, self.image_handle, self.imshape, logger) alp = 1 #cv2.imshow('image',im) #cv2.imwrite('/home/vasha/img.png', im) gl_utils.make_coord_system_norm_based() draw_gl_texture(im, interpolation=True, alpha=alp) if (self.record_ximea): if not self.camera_open: logger.info('Camera Not Open!') self.record_ximea = False
def gl_display(self): """ use gl calls to render at least: the published position of the reference better: show the detected postion even if not published """ if self.active: draw_points_norm([self.smooth_pos], size=15, color=RGBA(1.0, 1.0, 0.0, 0.5)) if self.active and len(self.markers): # draw the largest ellipse of all detected markers for marker in self.markers: e = marker["ellipses"][-1] pts = cv2.ellipse2Poly( (int(e[0][0]), int(e[0][1])), (int(e[1][0] / 2), int(e[1][1] / 2)), int(e[-1]), 0, 360, 15, ) draw_polyline(pts, color=RGBA(0.0, 1.0, 0, 1.0)) if len(self.markers) > 1: draw_polyline( pts, 1, RGBA(1.0, 0.0, 0.0, 0.5), line_type=GL_POLYGON ) # draw indicator on the first detected marker if self.counter and self.markers[0]["marker_type"] == "Ref": e = self.markers[0]["ellipses"][-1] pts = cv2.ellipse2Poly( (int(e[0][0]), int(e[0][1])), (int(e[1][0] / 2), int(e[1][1] / 2)), int(e[-1]), 0, 360, 360 // self.counter_max, ) indicator = [e[0]] + pts[self.counter :].tolist()[::-1] + [e[0]] draw_polyline( indicator, color=RGBA(0.1, 0.5, 0.7, 0.8), line_type=GL_POLYGON ) # draw indicator on the stop marker(s) if self.auto_stop: for marker in self.markers: if marker["marker_type"] == "Stop": e = marker["ellipses"][-1] pts = cv2.ellipse2Poly( (int(e[0][0]), int(e[0][1])), (int(e[1][0] / 2), int(e[1][1] / 2)), int(e[-1]), 0, 360, 360 // self.auto_stop_max, ) indicator = [e[0]] + pts[self.auto_stop :].tolist() + [e[0]] draw_polyline( indicator, color=RGBA(8.0, 0.1, 0.1, 0.8), line_type=GL_POLYGON, ) else: pass
def gl_display(self): for pt, a in self.pupil_display_list: # This could be faster if there would be a method to also add multiple colors per point draw_points_norm([pt], size=35, color=RGBA(1.0, 0.2, 0.4, a))
def gl_display(self): if(self.calibration_crosses): low_v = 0.15 mid_v = 0.5 high_v = 0.85 low_h = 0.1 mid_h = 0.5 high_h = 0.9 s = 300 c = RGBA(1.0, 1.0, 1.0, 0.5) draw_points_norm([(low_h,low_v)], size=s, color=c) draw_points_norm([(low_h,mid_v)], size=s, color=c) draw_points_norm([(low_h,high_v)], size=s, color=c) draw_points_norm([(high_h,low_v)], size=s, color=c) draw_points_norm([(high_h,mid_v)], size=s, color=c) draw_points_norm([(high_h,high_v)], size=s, color=c) draw_points_norm([(mid_h,low_v)], size=s, color=c) draw_points_norm([(mid_h,mid_v)], size=s, color=c) draw_points_norm([(mid_h,high_v)], size=s, color=c)
def gl_display(self): draw_points_norm(self.pupil_display_list, size=35, color=RGBA(1., .2, .4, .6))
def gl_display(self): draw_points_norm(self.pupil_display_list, size=35, color=RGBA(1.,.2,.4,.6))
def gl_display(self): if self.detected: draw_points_norm([self.pos], size=self.r, color=RGBA(0., 1., 0., .5))
def gl_display(self): if self.detected: draw_points_norm([self.pos],size=self.r,color=RGBA(0.,1.,0.,.5))