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_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): 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): 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 idx in range(1, len(self.queue)): newest = self.queue[-1]['timestamp'] current = self.queue[idx]['timestamp'] normalized_age = 1 - (newest - current) / self.store_duration res_alpha = self.min_alpha + (self.max_alpha - self.min_alpha) * normalized_age draw_polyline_norm( [self.queue[idx - 1]['norm_pos'], self.queue[idx]['norm_pos']], thickness=int(self.g_pool.gui.scale * 10 + 1), color=RGBA(1., 0.2, 0.4, res_alpha))
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_draw_frame(self, img_size, color=(1.0, 0.2, 0.6, 1.0), highlight=False, surface_mode=False, marker_mode=False): """ draw surface and markers """ if self.detected: r, g, b, a = color 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) if highlight: draw_polyline_norm(frame.reshape((5, 2)), 1, RGBA(r, g, b, a * .1), line_type=GL_POLYGON) draw_polyline_norm(frame.reshape((5, 2)), 1, RGBA(r, g, b, a * alpha)) draw_polyline_norm(hat.reshape((4, 2)), 1, RGBA(r, g, b, a * alpha)) text_anchor = frame.reshape((5, -1))[2] text_anchor[1] = 1 - text_anchor[1] text_anchor *= img_size[1], img_size[0] text_anchor = text_anchor[0], text_anchor[1] - 75 surface_edit_anchor = text_anchor[0], text_anchor[1] + 25 marker_edit_anchor = text_anchor[0], text_anchor[1] + 50 if marker_mode: draw_points([marker_edit_anchor], color=RGBA(0, .8, .7)) else: draw_points([marker_edit_anchor]) if surface_mode: draw_points([surface_edit_anchor], color=RGBA(0, .8, .7)) else: draw_points([surface_edit_anchor]) self.glfont.set_blur(3.9) self.glfont.set_color_float((0, 0, 0, .8)) self.glfont.draw_text(text_anchor[0] + 15, text_anchor[1] + 6, self.marker_status()) self.glfont.draw_text(surface_edit_anchor[0] + 15, surface_edit_anchor[1] + 6, 'edit surface') self.glfont.draw_text(marker_edit_anchor[0] + 15, marker_edit_anchor[1] + 6, 'add/remove markers') self.glfont.set_blur(0.0) self.glfont.set_color_float((0.1, 8., 8., .9)) self.glfont.draw_text(text_anchor[0] + 15, text_anchor[1] + 6, self.marker_status()) self.glfont.draw_text(surface_edit_anchor[0] + 15, surface_edit_anchor[1] + 6, 'edit surface') self.glfont.draw_text(marker_edit_anchor[0] + 15, marker_edit_anchor[1] + 6, 'add/remove markers')
def gl_draw_frame(self,img_size,color = (1.0,0.2,0.6,1.0),highlight=False,surface_mode=False,marker_mode=False): """ draw surface and markers """ if self.detected: r,g,b,a = color 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) if highlight: draw_polyline_norm(frame.reshape((5,2)),1,RGBA(r,g,b,a*.1),line_type=GL_POLYGON) draw_polyline_norm(frame.reshape((5,2)),1,RGBA(r,g,b,a*alpha)) draw_polyline_norm(hat.reshape((4,2)),1,RGBA(r,g,b,a*alpha)) text_anchor = frame.reshape((5,-1))[2] text_anchor[1] = 1-text_anchor[1] text_anchor *=img_size[1],img_size[0] text_anchor = text_anchor[0],text_anchor[1]-75 surface_edit_anchor = text_anchor[0],text_anchor[1]+25 marker_edit_anchor = text_anchor[0],text_anchor[1]+50 if self.defined: if marker_mode: draw_points([marker_edit_anchor],color=RGBA(0,.8,.7)) else: draw_points([marker_edit_anchor]) if surface_mode: draw_points([surface_edit_anchor],color=RGBA(0,.8,.7)) else: draw_points([surface_edit_anchor]) self.glfont.set_blur(3.9) self.glfont.set_color_float((0,0,0,.8)) self.glfont.draw_text(text_anchor[0]+15,text_anchor[1]+6,self.marker_status()) self.glfont.draw_text(surface_edit_anchor[0]+15,surface_edit_anchor[1]+6,'edit surface') self.glfont.draw_text(marker_edit_anchor[0]+15,marker_edit_anchor[1]+6,'add/remove markers') self.glfont.set_blur(0.0) self.glfont.set_color_float((0.1,8.,8.,.9)) self.glfont.draw_text(text_anchor[0]+15,text_anchor[1]+6,self.marker_status()) self.glfont.draw_text(surface_edit_anchor[0]+15,surface_edit_anchor[1]+6,'edit surface') self.glfont.draw_text(marker_edit_anchor[0]+15,marker_edit_anchor[1]+6,'add/remove markers') else: progress = (self.build_up_status/float(self.required_build_up))*100 progress_text = '%.0f%%'%progress self.glfont.set_blur(3.9) self.glfont.set_color_float((0,0,0,.8)) self.glfont.draw_text(text_anchor[0]+15,text_anchor[1]+6,self.marker_status()) self.glfont.draw_text(surface_edit_anchor[0]+15,surface_edit_anchor[1]+6,'Learning affiliated markers...') self.glfont.draw_text(marker_edit_anchor[0]+15,marker_edit_anchor[1]+6,progress_text) self.glfont.set_blur(0.0) self.glfont.set_color_float((0.1,8.,8.,.9)) self.glfont.draw_text(text_anchor[0]+15,text_anchor[1]+6,self.marker_status()) self.glfont.draw_text(surface_edit_anchor[0]+15,surface_edit_anchor[1]+6,'Learning affiliated markers...') self.glfont.draw_text(marker_edit_anchor[0]+15,marker_edit_anchor[1]+6,progress_text)
def gl_display(self): if self.inliers is not None: draw_polyline_norm(self.inliers, 1, RGBA(1., .5, 0., .5), line_type=GL_LINES) draw_polyline_norm(self.outliers, 1, RGBA(1., 0., 0., .5), line_type=GL_LINES) draw_polyline_norm(self.calib_bounds[:, 0], 1, RGBA(.0, 1., 0, .5), line_type=GL_LINE_LOOP)
def gl_display(self): if self.inliers is not None: draw_polyline_norm(self.inliers,1,RGBA(1.,.5,0.,.5),line_type=GL_LINES) draw_polyline_norm(self.outliers,1,RGBA(1.,0.,0.,.5),line_type=GL_LINES) draw_polyline_norm(self.calib_bounds[:,0],1,RGBA(.0,1.,0,.5),line_type=GL_LINE_LOOP)
def gl_display(self): if self.output_q.empty(): pass else: data = self.output_q.get() rect_points = data['rect_points'] class_names = data['class_names'] class_colors = data['class_colors'] height, width, _ = self.frame.shape dist_list = [] for point, name, color in zip(rect_points, class_names, class_colors): #define vertices necessary for drawing bounding boxes bottom_left, bottom_right = [ point['xmin'], 1 - point['ymax'] ], [point['xmax'], 1 - point['ymax']] top_left, top_right = [point['xmin'], 1 - point['ymin'] ], [point['xmax'], 1 - point['ymin']] top_left_label, top_right_label = top_left, [ point['xmin'] + len(name[0]) * 14 / width, 1 - point['ymin'] ] bottom_left_label, bottom_right_label = [ point['xmin'], 1 - (point['ymin'] + 30 / height) ], [ point['xmin'] + len(name[0]) * 14 / width, 1 - (point['ymin'] + 30 / height) ] center_bb = [(point['xmax'] + point['xmin']) / 2.0, ((1 - point['ymax']) + (1 - point['ymin'])) / 2.0] # Distance between gaze point and center of bounding box (center_bb) # for pt,a in self.pupil_display_list: # dist = math.hypot(center_bb[0]-pt[0], center_bb[1]-pt[1]) # # dist_list.append([dist, top_left[0]*width, (1-top_left[1])*height]) #for drawing text on detected object # dist_list.append([dist, [center_bb[0]*width, (1-center_bb[1])*height], name[0]]) # Distance between fixation point and center of bounding box (center_bb) if self.fixation_norm_pos: dist = math.hypot(center_bb[0] - self.fixation_norm_pos[0], center_bb[1] - self.fixation_norm_pos[1]) dist_list.append([ dist, [center_bb[0] * width, (1 - center_bb[1]) * height], name[0] ]) # Draw bounding box, label box, write label verts_label = [ top_left_label, top_right_label, bottom_right_label, bottom_left_label, top_left_label ] verts = [ top_left, top_right, bottom_right, bottom_left, top_left ] draw_polyline_norm(verts, thickness=5, color=RGBA(color[2] / 255, color[1] / 255, color[0] / 255, 1.0)) draw_polyline_norm(verts_label, thickness=5, color=RGBA(color[2] / 255, color[1] / 255, color[0] / 255, 1.0)) self.glfont.set_color_float((1.0, 1.0, 1.0, 1.0)) self.glfont.draw_text(top_left[0] * width, (1 - top_left[1]) * height, name[0]) self.glfont.set_align_string(v_align='left', h_align='top') # Draw an x on the detected_object closest to the fixation or gaze if dist_list: draw_x([sorted(dist_list)[0][1]], size=50, thickness=5, color=RGBA(color[2] / 255, color[1] / 255, color[0] / 255, .5)) self.label = sorted(dist_list)[0][2] label_q.put(self.label)