def gl_display(self): glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho(-self.h_pad, (self.frame_count)+self.h_pad, -self.v_pad, 1+self.v_pad,-1,1) # ranging from 0 to cache_len-1 (horizontal) and 0 to 1 (vertical) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() color1 = RGBA(.1,.9,.2,.5) color2 = RGBA(.1,.9,.9,.5) if self.in_mark != 0 or self.out_mark != self.frame_count: draw_polyline( [(self.in_mark,0),(self.out_mark,0)],color=color1,thickness=2) draw_points([(self.in_mark,0),],color=color1,size=10) draw_points([(self.out_mark,0),],color=color1,size=10) if self.sections: for s in self.sections: if self.sections.index(s) != self.focus: draw_polyline( [(s[0],0),(s[1],0)],color=RGBA(.1,.9,.9,.2),thickness=2) for mark in s: draw_points([(mark,0),],color=color2,size=5) if self.mid_sections: for m in self.mid_sections: draw_points([(m,0),],color=RGBA(.1,.9,.9,.1),size=10) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix()
def gl_display(self): glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho( -self.h_pad, (self.frame_count) + self.h_pad, -self.v_pad, 1 + self.v_pad, -1, 1 ) # ranging from 0 to cache_len-1 (horizontal) and 0 to 1 (vertical) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() color1 = RGBA(.1, .9, .2, 1.) color2 = RGBA(.1, .9, .2, 1.) if self.in_mark != 0 or self.out_mark != self.frame_count: draw_polyline([(self.in_mark, 0), (self.out_mark, 0)], color=color1, thickness=20.) draw_points([ (self.in_mark, 0), ], color=color2, size=20) draw_points([ (self.out_mark, 0), ], color=color2, size=20) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix()
def draw_ellipse(ellipse: Dict, rgba: Tuple, thickness: float, draw_center: bool = False): try: pts = cv2.ellipse2Poly( center=(int(ellipse["center"][0]), int(ellipse["center"][1])), axes=(int(ellipse["axes"][0] / 2), int(ellipse["axes"][1] / 2)), angle=int(ellipse["angle"]), arcStart=0, arcEnd=360, delta=8, ) except Exception as e: # Known issues: # - There are reports of negative eye_ball axes when drawing the 3D eyeball # outline, which will raise cv2.error. TODO: Investigate cause in detectors. logger.debug("Error drawing ellipse! Skipping...\n" f"ellipse: {ellipse}\n" f"{type(e)}: {e}") draw_polyline(pts, thickness, RGBA(*rgba)) if draw_center: draw_points( [ellipse["center"]], size=20, color=RGBA(*rgba), sharpness=1.0, )
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 draw_pupil_outline(pupil_detection_result_2d): """Requires `"ellipse" in pupil_detection_result_2d`""" if pupil_detection_result_2d["confidence"] <= 0.0: return try: pts = cv2.ellipse2Poly( ( int(pupil_detection_result_2d["ellipse"]["center"][0]), int(pupil_detection_result_2d["ellipse"]["center"][1]), ), ( int(pupil_detection_result_2d["ellipse"]["axes"][0] / 2), int(pupil_detection_result_2d["ellipse"]["axes"][1] / 2), ), int(pupil_detection_result_2d["ellipse"]["angle"]), 0, 360, 15, ) except ValueError: # Happens when converting 'nan' to int # TODO: Investigate why results are sometimes 'nan' return confidence = pupil_detection_result_2d["confidence"] * 0.7 draw_polyline(pts, 1, RGBA(1.0, 0, 0, confidence)) draw_points( [pupil_detection_result_2d["ellipse"]["center"]], size=20, color=RGBA(1.0, 0.0, 0.0, confidence), sharpness=1.0, )
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 update_window(self, eye, points, found_circle): if self._window != None: glfwMakeContextCurrent(self._window) self.clear_gl_screen() self.trackball.push() glLoadMatrixf(self.get_anthropomorphic_matrix()) self.draw_coordinate_system(4) eye_position = eye[0] eye_radius = eye[1] self.draw_sphere(eye_position, eye_radius) if points: draw_points(points, size=3, color=RGBA(1., 0, 0, 1.0), sharpness=1.0) self.draw_circle(found_circle[0], found_circle[1], found_circle[2], color=RGBA(1., 1, 0, 0.5)) self.trackball.pop() glfwSwapBuffers(self._window) glfwPollEvents() return True
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 """ # debug mode within world will show green ellipses around detected ellipses if self.active: for marker in self.markers: e = marker["ellipses"][-1] # outermost ellipse 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, 1, RGBA(0.0, 1.0, 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.GL_POLYGON )
def gl_display(self): """ This is where we can draw to any gl surface by default this is the main window, below we change that """ # active our window active_window = glfwGetCurrentContext() glfwMakeContextCurrent(self.window) # start drawing things: gl_utils.clear_gl_screen() # set coordinate system to be between 0 and 1 of the extents of the window gl_utils.make_coord_system_norm_based() # draw the image draw_gl_texture(self.img) # make coordinte system identical to the img pixel coordinate system gl_utils.make_coord_system_pixel_based(self.img.shape) # draw some points on top of the image # notice how these show up in our window but not in the main window draw_points([(200, 400), (600, 400)], color=RGBA(0., 4., .8, .8), size=self.my_var) draw_polyline([(200, 400), (600, 400)], color=RGBA(0., 4., .8, .8), thickness=3) # since this is our own window we need to swap buffers in the plugin glfwSwapBuffers(self.window) # and finally reactive the main window glfwMakeContextCurrent(active_window)
def gl_display_in_window(self): active_window = glfwGetCurrentContext() if glfwWindowShouldClose(self._window): self.close_window() return glfwMakeContextCurrent(self._window) clear_gl_screen() hdpi_factor = glfwGetFramebufferSize( self._window)[0] / glfwGetWindowSize(self._window)[0] r = self.marker_scale * hdpi_factor gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() p_window_size = glfwGetFramebufferSize(self._window) gl.glOrtho(0, p_window_size[0], p_window_size[1], 0, -1, 1) # Switch back to Model View Matrix gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() def map_value(value, in_range=(0, 1), out_range=(0, 1)): ratio = (out_range[1] - out_range[0]) / (in_range[1] - in_range[0]) return (value - in_range[0]) * ratio + out_range[0] pad = 90 * r screen_pos = map_value( self.display_pos[0], out_range=(pad, p_window_size[0] - pad)), map_value( self.display_pos[1], out_range=(p_window_size[1] - pad, pad)) alpha = 1.0 #interp_fn(self.screen_marker_state,0.,1.,float(self.sample_duration+self.lead_in+self.lead_out),float(self.lead_in),float(self.sample_duration+self.lead_in)) r2 = 2 * r draw_points([screen_pos], size=60 * r2, color=RGBA(0., 0., 0., alpha), sharpness=0.9) draw_points([screen_pos], size=38 * r2, color=RGBA(1., 1., 1., alpha), sharpness=0.8) draw_points([screen_pos], size=19 * r2, color=RGBA(0., 0., 0., alpha), sharpness=0.55) # some feedback on the detection state color = RGBA(0., .8, 0., alpha) if len( self.markers) and self.on_position else RGBA(0.8, 0., 0., alpha) draw_points([screen_pos], size=3 * r2, color=color, sharpness=0.5) if self.clicks_to_close < 5: self.glfont.set_size(int(p_window_size[0] / 30.)) self.glfont.draw_text( p_window_size[0] / 2., p_window_size[1] / 4., 'Touch {} more times to cancel calibration.'.format( self.clicks_to_close)) 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() 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_polyline(verts=[(0, 0), (self.current_frame_index, 0)], color=RGBA(*color1)) draw_polyline(verts=[(self.current_frame_index, 0), (self.frame_count, 0)], color=RGBA(.5, .5, .5, .5)) draw_points([(self.current_frame_index, 0)], color=RGBA(*color1), size=40) draw_points([(self.current_frame_index, 0)], color=RGBA(*color2), size=10) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix()
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 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.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.GL_POLYGON)
def draw_ellipse( ellipse: Dict, rgba: Tuple, thickness: float, draw_center: bool = False ): try: pts = cv2.ellipse2Poly( center=(int(ellipse["center"][0]), int(ellipse["center"][1])), axes=(int(ellipse["axes"][0] / 2), int(ellipse["axes"][1] / 2)), angle=int(ellipse["angle"]), arcStart=0, arcEnd=360, delta=8, ) except Exception as e: # Known issues: # - There are reports of negative eye_ball axes when drawing the 3D eyeball # outline, which will raise cv2.error. TODO: Investigate cause in detectors. # - There was a case where all values in the ellipse where 'NaN', which raises # ValueError: cannot convert float NaN to integer. TODO: Investigate how we # even got here, since calls to this function are confidence-gated! logger.debug( "Error drawing ellipse! Skipping...\n" f"Ellipse: {ellipse}\n" f"Color: {rgba}\n" f"Error: {type(e)}: {e}" ) return draw_polyline(pts, thickness, RGBA(*rgba)) if draw_center: _draw_circle_filled( tuple(ellipse["center"]), size=3, color=RGBA(*rgba), )
def draw_circle(self, circle_center, circle_normal, circle_radius, color=RGBA(1.1, 0.2, .8), num_segments=20): vertices = [] vertices.append((0, 0, 0)) # circle center #create circle vertices in the xy plane for i in np.linspace(0.0, 2.0 * math.pi, num_segments): x = math.sin(i) y = math.cos(i) z = 0 vertices.append((x, y, z)) glPushMatrix() glMatrixMode(GL_MODELVIEW) glLoadMatrixf( self.get_pupil_transformation_matrix(circle_normal, circle_center, circle_radius)) draw_polyline((vertices), color=color, line_type=GL_TRIANGLE_FAN) # circle draw_polyline([(0, 0, 0), (0, 0, 4)], color=RGBA(0, 0, 0), line_type=GL_LINES) #normal glPopMatrix()
def gl_display(self): """ Display marker and surface info inside world screen """ if self.mode == "Show Markers and Surfaces": for m in self.markers: hat = np.array( [[[0, 0], [0, 1], [.5, 1.3], [1, 1], [1, 0], [0, 0]]], dtype=np.float32) hat = cv2.perspectiveTransform(hat, m_marker_to_screen(m)) if m['perimeter'] >= self.min_marker_perimeter and m[ 'id_confidence'] > self.min_id_confidence: draw_polyline(hat.reshape((6, 2)), color=RGBA(0.1, 1., 1., .5)) draw_polyline(hat.reshape((6, 2)), color=RGBA(0.1, 1., 1., .3), line_type=GL_POLYGON) else: draw_polyline(hat.reshape((6, 2)), color=RGBA(0.1, 1., 1., .5)) for s in self.surfaces: if s not in self.edit_surfaces and s is not self.marker_edit_surface: s.gl_draw_frame(self.img_shape) for s in self.edit_surfaces: s.gl_draw_frame(self.img_shape, highlight=True, surface_mode=True) s.gl_draw_corners() if self.marker_edit_surface: inc = [] exc = [] for m in self.markers: if m['perimeter'] >= self.min_marker_perimeter: if m['id'] in self.marker_edit_surface.markers: inc.append(m['centroid']) else: exc.append(m['centroid']) draw_points(exc, size=20, color=RGBA(1., 0.5, 0.5, .8)) draw_points(inc, size=20, color=RGBA(0.5, 1., 0.5, .8)) self.marker_edit_surface.gl_draw_frame(self.img_shape, color=(0.0, 0.9, 0.6, 1.0), highlight=True, marker_mode=True) elif self.mode == 'Show Heatmaps': for s in self.surfaces: if self.g_pool.app != 'player': s.generate_heatmap() s.gl_display_heatmap() for s in self.surfaces: if self.locate_3d: s.gl_display_in_window_3d(self.g_pool.image_tex) else: s.gl_display_in_window(self.g_pool.image_tex)
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_display_in_window_3d(self, world_tex): """ here we map a selected surface onto a seperate window. """ K, img_size = ( self.g_pool.capture.intrinsics.K, self.g_pool.capture.intrinsics.resolution, ) if self._window and self.camera_pose_3d is not None: active_window = glfwGetCurrentContext() glfwMakeContextCurrent(self._window) glClearColor(0.8, 0.8, 0.8, 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearDepth(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) self.trackball.push() glMatrixMode(GL_MODELVIEW) draw_coordinate_system(l=self.real_world_size["x"]) glPushMatrix() glScalef(self.real_world_size["x"], self.real_world_size["y"], 1) draw_polyline( [[0, 0], [0, 1], [1, 1], [1, 0]], color=RGBA(0.5, 0.3, 0.1, 0.5), thickness=3, ) glPopMatrix() # Draw the world window as projected onto the plane using the homography mapping glPushMatrix() glScalef(self.real_world_size["x"], self.real_world_size["y"], 1) # cv uses 3x3 gl uses 4x4 tranformation matricies m = cvmat_to_glmat(self.m_from_screen) glMultMatrixf(m) glTranslatef(0, 0, -0.01) world_tex.draw() draw_polyline( [[0, 0], [0, 1], [1, 1], [1, 0]], color=RGBA(0.5, 0.3, 0.6, 0.5), thickness=3, ) glPopMatrix() # Draw the camera frustum and origin using the 3d tranformation obtained from solvepnp glPushMatrix() glMultMatrixf(self.camera_pose_3d.T.flatten()) draw_frustum(img_size, K, 150) glLineWidth(1) draw_frustum(img_size, K, 0.1) draw_coordinate_system(l=5) glPopMatrix() self.trackball.pop() glfwSwapBuffers(self._window) glfwMakeContextCurrent(active_window)
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_in_window(self): active_window = glfwGetCurrentContext() glfwMakeContextCurrent(self._window) clear_gl_screen() hdpi_factor = glfwGetFramebufferSize( self._window)[0] / glfwGetWindowSize(self._window)[0] r = 110 * self.marker_scale * hdpi_factor gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() p_window_size = glfwGetWindowSize(self._window) gl.glOrtho(0, p_window_size[0], p_window_size[1], 0, -1, 1) # Switch back to Model View Matrix gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() def map_value(value, in_range=(0, 1), out_range=(0, 1)): ratio = (out_range[1] - out_range[0]) / (in_range[1] - in_range[0]) return (value - in_range[0]) * ratio + out_range[0] pad = .6 * r screen_pos = map_value( self.display_pos[0], out_range=(pad, p_window_size[0] - pad)), map_value( self.display_pos[1], out_range=(p_window_size[1] - pad, pad)) alpha = interp_fn( self.screen_marker_state, 0., 1., float(self.sample_duration + self.lead_in + self.lead_out), float(self.lead_in), float(self.sample_duration + self.lead_in)) draw_concentric_circles(screen_pos, r, 6, alpha) #some feedback on the detection state if self.detected and self.on_position: draw_points([screen_pos], size=5, color=RGBA(0., .8, 0., alpha), sharpness=0.5) else: draw_points([screen_pos], size=5, color=RGBA(0.8, 0., 0., alpha), sharpness=0.5) if self.clicks_to_close < 5: self.glfont.set_size(int(p_window_size[0] / 30.)) self.glfont.draw_text( p_window_size[0] / 2., p_window_size[1] / 4., 'Touch %s more times to cancel calibration.' % self.clicks_to_close) glfwSwapBuffers(self._window) glfwMakeContextCurrent(active_window)
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): 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_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 # ############################ hdpi_factor = glfwGetFramebufferSize(self._window)[0]/glfwGetWindowSize(self._window)[0] r = 110*self.marker_scale * hdpi_factor gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() p_window_size = glfwGetWindowSize(self._window) # compensate for radius of marker gl.glOrtho(-r*.6,p_window_size[0]+r*.6,p_window_size[1]+r*.7,-r*.7 ,-1,1) # 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) alpha = interp_fn(self.screen_marker_state,0.,1.,float(self.sample_duration+self.lead_in+self.lead_out),float(self.lead_in),float(self.sample_duration+self.lead_in)) draw_concentric_circles(screen_pos,r,6,alpha) #some feedback on the detection state if self.detected and self.on_position: draw_points([screen_pos],size=5,color=RGBA(0.,1.,0.,alpha),sharpness=0.95) else: draw_points([screen_pos],size=5,color=RGBA(1.,0.,0.,alpha),sharpness=0.95) if self.clicks_to_close <5: self.glfont.set_size(int(p_window_size[0]/30.)) self.glfont.draw_text(p_window_size[0]/2.,p_window_size[1]/4.,'Touch %s more times to cancel calibration.'%self.clicks_to_close) glfwSwapBuffers(self._window) glfwMakeContextCurrent(active_window)
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 not self.is_active: return for marker in self.__previously_detected_markers: # draw the largest ellipse of all detected 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.__previously_detected_markers) > 1: draw_polyline(pts, 1, RGBA(1.0, 0.0, 0.0, 0.5), line_type=gl.GL_POLYGON) # draw indicator on the stop marker(s) 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._STOP_MARKER_FRAMES_NEEDED_TO_STOP, ) indicator = ( [e[0]] + pts[self.__auto_stop_tracker.detected_count:].tolist() + [e[0]]) draw_polyline(indicator, color=RGBA(8.0, 0.1, 0.1, 0.8), line_type=gl.GL_POLYGON)
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): 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_display_in_window(self): active_window = glfwGetCurrentContext() glfwMakeContextCurrent(self._window) clear_gl_screen() gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() p_window_size = glfwGetWindowSize(self._window) r = p_window_size[0] / 15.0 # compensate for radius of marker gl.glOrtho(-r, p_window_size[0] + r, p_window_size[1] + r, -r, -1, 1) # Switch back to Model View Matrix gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() # hacky way of scaling and fitting in different window rations/sizes grid = _make_grid() * min((p_window_size[0], p_window_size[1] * 5.5 / 4.0)) # center the pattern grid -= np.mean(grid) grid += (p_window_size[0] / 2 - r, p_window_size[1] / 2 + r) draw_points(grid, size=r, color=RGBA(0.0, 0.0, 0.0, 1), sharpness=0.95) if self.clicks_to_close < 5: self.glfont.set_size(int(p_window_size[0] / 30.0)) self.glfont.draw_text( p_window_size[0] / 2.0, p_window_size[1] / 4.0, "Touch {} more times to close window.".format(self.clicks_to_close), ) glfwSwapBuffers(self._window) glfwMakeContextCurrent(active_window)
def init_ui(self): # set up performace graphs: pid = os.getpid() ps = psutil.Process(pid) self.cpu_graph = graph.Bar_Graph() self.cpu_graph.pos = (20, 50) self.cpu_graph.update_fn = ps.cpu_percent self.cpu_graph.update_rate = 5 self.cpu_graph.label = "CPU %0.1f" self.fps_graph = graph.Bar_Graph() self.fps_graph.pos = (140, 50) self.fps_graph.update_rate = 5 self.fps_graph.label = "%0.0f FPS" self.conf0_graph = graph.Bar_Graph(max_val=1.0) self.conf0_graph.pos = (260, 50) self.conf0_graph.update_rate = 5 self.conf0_graph.label = "id0 conf: %0.2f" self.conf1_graph = graph.Bar_Graph(max_val=1.0) self.conf1_graph.pos = (380, 50) self.conf1_graph.update_rate = 5 self.conf1_graph.label = "id1 conf: %0.2f" self.conf_grad = ( RGBA(1.0, 0.0, 0.0, self.conf0_graph.color[3]), self.conf0_graph.color, ) self.on_window_resize(self.g_pool.main_window)
def gl_display_cache_bars(self): """""" padding = 20.0 frame_max = len(self.g_pool.timestamps ) # last marker is garanteed to be frame max. glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() width, height = self.g_pool.camera_render_size h_pad = padding * (frame_max - 2) / float(width) v_pad = padding * 1.0 / (height - 2) gluOrtho( -h_pad, (frame_max - 1) + h_pad, -v_pad, 1 + v_pad, -1, 1 ) # ranging from 0 to cache_len-1 (horizontal) and 0 to 1 (vertical) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() glTranslatef(0, -0.02, 0) color = (7.0, 0.1, 0.2, 8.0) draw_polyline( self.gl_display_ranges, color=RGBA(*color), line_type=GL_LINES, thickness=2.0, ) glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glPopMatrix()