def refresh(self, q): """Refresh the display if there is new data :q: TODO :returns: TODO """ while not q.empty(): self.message = q.get() if self.message is not None: map_points, poses, colors = self.message gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.0, 0.0, 0.0, 1.0) self.dcam.Activate(self.scam) if poses is not None: if poses.shape[0] >= 2: gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(poses[0:-1, :]) gl.glColor3f(1.0, 1.0, 0.0) pangolin.DrawCameras(poses[-1:, :]) if map_points is not None and colors is not None: if map_points.shape[0] != 0: gl.glPointSize(3) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(map_points, colors) pangolin.FinishFrame()
def viewer_refresh(self, q): while not q.empty(): self.state = q.get() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.0, 0.0, 0.0, 1.0) self.dcam.Activate(self.scam) if self.state is not None: if self.state[0].shape[0] >= 2: # draw poses gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.state[0][:-1]) if self.state[0].shape[0] >= 1: # draw current pose as yellow gl.glColor3f(1.0, 1.0, 0.0) pangolin.DrawCameras(self.state[0][-1:]) if self.state[1].shape[0] != 0: # draw keypoints gl.glPointSize(5) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(self.state[1], self.state[2]) pangolin.FinishFrame()
def viewer_refresh(self, data): top = None # get poses while not data.empty(): top = data.get() if top is None: return self.frames = top[0] self.points = top[1] gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.0, 0.0, 0.0, 1.0) self.dcam.Activate(self.scam) # draw all poses if self.frames is not None: gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.frames[:-1]) # draw world coordinates if self.points is not None and self.points.shape[0] > 0: colors = np.zeros((len(self.points), 3)) colors[:, 1] = 1 - self.points[:, 0] / 10.0 colors[:, 2] = 1 - self.points[:, 1] / 10.0 colors[:, 0] = 1 - self.points[:, 2] / 10.0 gl.glPointSize(2) gl.glColor3f(0.0, 0.0, 1.0) # # uncomment to draw points # pangolin.DrawPoints(self.points, colors) pangolin.FinishFrame()
def viewer_refresh(self, q): while not q.empty(): self.data = q.get() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.0, 0.0, 0.0, 1.0) self.dcam.Activate(self.scam) # drawing begins here # self.pose[2, 3] = self.pose[2, 3] - 0.1 # self.poses.append(np.linalg.inv(self.pose)) if self.data is not None: gl.glLineWidth(3) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.data[0]) if len(self.data) > 1: gl.glPointSize(5) points = self.data[1] colors = self.data[2] pangolin.DrawPoints(points, colors) pangolin.FinishFrame()
def viewer_refresh(self, q): if self.state is None or not q.empty(): self.state = q.get() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.0, 0.0, 0.0, 1.0) self.dcam.Activate(self.scam) if self.state is not None: if self.state[0].shape[0] >= 2: gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.state[0][:-1]) if self.state[0].shape[0] >= 1: gl.glColor3f(1.0, 1.0, 0.0) pangolin.DrawCameras(self.state[0][-1:]) if self.state[1].shape[0] != 0: gl.glPointSize(2) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(self.state[1], self.state[2]) pangolin.FinishFrame()
def viewer_refresh(self, q): if self.state is None or not q.empty(): self.state = q.get() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) self.dcam.Activate(self.scam) gl.glLineWidth(1) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.state[0]) gl.glPointSize(2) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(self.state[1]) pangolin.FinishFrame()
def main(): w, h = 640, 480 pangolin.CreateWindowAndBind('Main', 640, 480) gl.glEnable(gl.GL_DEPTH_TEST) # Create Interactive View in window scam = pangolin.OpenGlRenderState( pangolin.ProjectionMatrix(w, h, 420, 420, w//2, h//2, 0.2, 10000), pangolin.ModelViewLookAt(0, -10, -8, 0, 0, 0, 0, -1, 0)) handler = pangolin.Handler3D(scam) # Create Interactive View in window dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 0.0, 1.0, w/h) dcam.SetHandler(handler) # hack to avoid small Pangolin, no idea why it's *2 dcam.Resize(pangolin.Viewport(0,0,w*2,h*2)) dcam.Activate() poses = [] # pose = np.hstack((np.identity(3), np.zeros((3,1)))) pose = np.identity(4) poses.append(np.linalg.inv(pose)) while not pangolin.ShouldQuit(): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.0, 0.0, 0.0, 1.0) dcam.Activate(scam) pose[2, 3] = pose[2, 3] - 1 poses.append(np.linalg.inv(pose)) print(poses[-1]) gl.glLineWidth(3) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(poses) # pangolin.DrawCamera(pose) time.sleep(0.2) # pangolin.DrawCameras(np.linalg.inv(poses[-1])) # pangolin.DrawCameras(np.stack(poses, axis=0)) # print(np.stack(poses,axis=2).shape) pangolin.FinishFrame()
def viewer_refresh(self, q): if self.state is None or not q.empty(): self.state = q.get() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # gl.glClearColor(1.0, 1.0, 1.0, 1.0) gl.glClearColor(0.0, 0.0, 0.0, 1.0) self.dcam.Activate(self.scam) # draw poses gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.state[0]) # draw keypoints gl.glPointSize(5) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(self.state[1], self.state[2]) pangolin.FinishFrame()
def main(): pango.CreateWindowAndBind('frustrum render', 640, 480) # Projection and ModelView Matrices scam = pango.OpenGlRenderState( pango.ProjectionMatrix(640, 480, 2000, 2000, 320, 240, 0.1, 5000), pango.ModelViewLookAt(0, -50, -10, 0, 0, 0, 0, -1, 0)) #pango.AxisDirection.AxisY)) handler = pango.Handler3D(scam) # Interactive View in Window disp_cam = pango.CreateDisplay() disp_cam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0 / 480.0) disp_cam.SetHandler(handler) # create and append pose matrices for cameras pose = np.identity(4) poses = [] for i in range(3): poses.append(np.linalg.inv(pose)) pose[2, 3] -= 1 while not pango.ShouldQuit(): # Clear screen gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.15, 0.15, 0.15, 0.0) disp_cam.Activate(scam) # Render Cameras gl.glLineWidth(2) gl.glColor3f(1.0, 0.0, 1.0) pango.DrawCamera(poses[0]) gl.glColor3f(0.2, 1.0, 0.2) pango.DrawCameras(poses[1:-1]) gl.glColor3f(1.0, 1.0, 1.0) pango.DrawCamera(poses[-1]) # End frame update pango.FinishFrame()
def render_map(self, q): if (self.currState is None) or (not q.empty()): self.currState = q.get() # Extract points and poses gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) self.dcam.Activate(self.scam) # Draw poses #gl.glPointSize(10) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawCameras(self.currState[0]) # Draw points gl.glPointSize(2) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawPoints(self.currState[1]) pangolin.FinishFrame()
def refresh(self): #clear and activate screen gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.15, 0.15, 0.15, 0.0) #gl.glClearColor(1.0, 1.0, 1.0, 0.0) self.dcam.Activate(self.scam) # render gl.glLineWidth(1) # render cameras if len(self.nodes) > 1: gl.glColor3f(1.0, 1.0, 1.0) pango.DrawCameras(self.nodes) # render edges if len(self.edges) > 1: gl.glColor3f(0.0, 0.8, 0.5) pango.DrawLines(self.edges[:, 0, :-1, -1], self.edges[:, 1, :-1, -1]) pango.FinishFrame()
def draw(self): q = self.q self.draw_init() while not pangolin.ShouldQuit(): try: while not q.empty(): state = q.get() if state is not None: self.cams.append(state[0]) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) self.dcam.Activate(self.scam) # Draw cam gl.glLineWidth(2) gl.glColor3f(0.0, 1.0, 0.0) # pangolin.DrawCamera(state[0], 0.5, 0.75, 0.8) pangolin.DrawCameras(self.cams) pangolin.FinishFrame() except: continue
def viewer_refresh(self, q): if self.state is None or not q.empty(): self.state = q.get() # turn state into points #ppts = np.array([d[:3, 3] for d in self.state[0]]) spts = np.array(self.state[1]) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) self.dcam.Activate(self.scam) # draw poses gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.state[0]) #draw keypoints gl.glPointSize(2) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(spts) pangolin.FinishFrame()
def view(self): pangolin.CreateWindowAndBind('Viewer', 1024, 768) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) panel = pangolin.CreatePanel('menu') panel.SetBounds(0.5, 1.0, 0.0, 175 / 1024.) # checkbox m_follow_camera = pangolin.VarBool('menu.Follow Camera', value=True, toggle=True) m_show_points = pangolin.VarBool('menu.Show Points', True, True) m_show_lines = pangolin.VarBool('menu.Show Lines', True, True) m_show_keyframes = pangolin.VarBool('menu.Show KeyFrames', True, True) m_show_graph = pangolin.VarBool('menu.Show Graph', True, True) m_show_image = pangolin.VarBool('menu.Show Image', True, True) # button m_replay = pangolin.VarBool('menu.Replay', value=False, toggle=False) m_refresh = pangolin.VarBool('menu.Refresh', False, False) m_reset = pangolin.VarBool('menu.Reset', False, False) if self.config is None: width, height = 400, 250 viewpoint_x = 0 viewpoint_y = -500 # -10 viewpoint_z = -100 # -0.1 viewpoint_f = 2000 camera_width = 1. else: width = self.config.view_image_width height = self.config.view_image_height viewpoint_x = self.config.view_viewpoint_x viewpoint_y = self.config.view_viewpoint_y viewpoint_z = self.config.view_viewpoint_z viewpoint_f = self.config.view_viewpoint_f camera_width = self.config.view_camera_width proj = pangolin.ProjectionMatrix(1024, 768, viewpoint_f, viewpoint_f, 512, 389, 0.1, 5000) look_view = pangolin.ModelViewLookAt(viewpoint_x, viewpoint_y, viewpoint_z, 0, 0, 0, 0, -1, 0) # Camera Render Object (for view / scene browsing) scam = pangolin.OpenGlRenderState(proj, look_view) # Add named OpenGL viewport to window and provide 3D Handler dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 175 / 1024., 1.0, -1024 / 768.) dcam.SetHandler(pangolin.Handler3D(scam)) # image # width, height = 400, 130 dimg = pangolin.Display('image') dimg.SetBounds(0, height / 768., 0.0, width / 1024., 1024 / 768.) dimg.SetLock(pangolin.Lock.LockLeft, pangolin.Lock.LockTop) texture = pangolin.GlTexture(width, height, gl.GL_RGB, False, 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) image = np.ones((height, width, 3), 'uint8') pose = pangolin.OpenGlMatrix() # identity matrix following = True active = [] replays = [] graph = [] loops = [] mappoints = DynamicArray(shape=(3, )) maplines = DynamicArray(shape=(6, )) colors = DynamicArray(shape=(3, )) cameras = DynamicArray(shape=(4, 4)) active_lines = [] line_colors = [] gnd_mesh = None while not pangolin.ShouldQuit(): if not self.q_pose.empty(): pose.m = self.q_pose.get() follow = m_follow_camera.Get() if follow and following: scam.Follow(pose, True) elif follow and not following: scam.SetModelViewMatrix(look_view) scam.Follow(pose, True) following = True elif not follow and following: following = False gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) dcam.Activate(scam) # show graph if not self.q_graph.empty(): graph = self.q_graph.get() loops = np.array([_[0] for _ in graph if _[1] == 2]) graph = np.array([_[0] for _ in graph if _[1] < 2]) if m_show_graph.Get(): if len(graph) > 0: gl.glLineWidth(1) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawLines(graph, 3) if len(loops) > 0: gl.glLineWidth(2) gl.glColor3f(0.0, 0.0, 0.0) pangolin.DrawLines(loops, 4) gl.glPointSize(4) gl.glColor3f(1.0, 0.0, 0.0) gl.glBegin(gl.GL_POINTS) gl.glVertex3d(pose[0, 3], pose[1, 3], pose[2, 3]) gl.glEnd() # if not self.q_ground.empty(): # gnd_mesh = self.q_ground.get() if gnd_mesh is not None: gl.glLineWidth(2) gl.glColor3f(0.5, 0.25, 0.5) pangolin.DrawLines(gnd_mesh, 2) # Show mappoints if not self.q_points.empty(): pts, code = self.q_points.get() cls, code = self.q_colors.get() if code == 1: # append new points mappoints.extend(pts) colors.extend(cls) elif code == 0: # refresh all points mappoints.clear() mappoints.extend(pts) colors.clear() colors.extend(cls) if m_show_points.Get(): gl.glPointSize(4) # easily draw millions of points pangolin.DrawPoints(mappoints.array(), colors.array()) if not self.q_active.empty(): active = self.q_active.get() gl.glPointSize(5) gl.glBegin(gl.GL_POINTS) gl.glColor3f(1.0, 0.0, 0.0) for point in active: gl.glVertex3f(*point) gl.glEnd() if not self.q_lines.empty(): lines, code = self.q_lines.get() maplines.extend(lines) if m_show_lines.Get(): gl.glLineWidth(1) gl.glColor3f(1.0, 0.0, 0.5) pangolin.DrawLines(maplines.array(), 2) if not self.q_active_lines.empty(): active_lines, line_colors = np.array( self.q_active_lines.get()) if active_lines is not None: for act_line, color in zip(active_lines, line_colors): c = (color[2] / 255, color[1] / 255, color[0] / 255) act_line = act_line.reshape((1, 6)) gl.glLineWidth(5) gl.glColor3f(*c) pangolin.DrawLines(act_line, 2) if len(replays) > 0: n = 300 gl.glPointSize(4) gl.glColor3f(1.0, 0.0, 0.0) gl.glBegin(gl.GL_POINTS) for point in replays[:n]: gl.glVertex3f(*point) gl.glEnd() replays = replays[n:] # show cameras if not self.q_camera.empty(): cams = self.q_camera.get() if len(cams) > 20: cameras.clear() cameras.extend(cams) if m_show_keyframes.Get(): gl.glLineWidth(1) gl.glColor3f(0.0, 0.0, 1.0) pangolin.DrawCameras(cameras.array(), camera_width) # show image if not self.q_image.empty(): image = self.q_image.get() if image.ndim == 3: image = image[::-1, :, ::-1] else: image = np.repeat(image[::-1, :, np.newaxis], 3, axis=2) image = cv2.resize(image, (width, height)) if m_show_image.Get(): texture.Upload(image, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) dimg.Activate() gl.glColor3f(1.0, 1.0, 1.0) texture.RenderToViewport() if pangolin.Pushed(m_replay): replays = mappoints.array() if pangolin.Pushed(m_reset): m_show_graph.SetVal(True) m_show_keyframes.SetVal(True) m_show_points.SetVal(True) m_show_image.SetVal(True) m_follow_camera.SetVal(True) follow_camera = True if pangolin.Pushed(m_refresh): self.q_refresh.put(True) pangolin.FinishFrame()
def UpdatePointsThread(self, PointsQueue, PoseQueue): import OpenGL.GL as gl import pangolin pangolin.CreateWindowAndBind('Main', 640, 480) gl.glEnable(gl.GL_DEPTH_TEST) # Define Projection and initial ModelView matrix # scam = pangolin.OpenGlRenderState( # pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.2, 100), # pangolin.ModelViewLookAt(-2, 2, -2, # 0, 0, 0, # pangolin.AxisDirection.AxisY)) scam = pangolin.OpenGlRenderState( pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.2, 10000), pangolin.ModelViewLookAt(-2, 2, -2, 0, 0, 0, pangolin.AxisDirection.AxisY)) handler = pangolin.Handler3D(scam) # Create Interactive View in window dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0 / 480.0) dcam.SetHandler(handler) points = None cameras = None while not pangolin.ShouldQuit(): if points is None: try: points = PointsQueue.get() except: continue else: points = np.vstack((points, PointsQueue.get())) if cameras is None: try: cameras = [PoseQueue.get()] except: continue else: cameras.append(PoseQueue.get()) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) dcam.Activate(scam) # Render OpenGL Cube pangolin.glDrawColouredCube() gl.glPointSize(2) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawPoints(points) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawCameras(cameras) # gl.glPointSize(5) # gl.glColor3f(1.0, 0.0, 0.0) # pangolin.DrawPoints(self.state[1], self.state[2]) #assert 1==0 pangolin.FinishFrame()
def glMainLoop(self): self.logger.info("Running gl viewer ...") flag = False pangolin.CreateWindowAndBind('Main', 640, 480) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) panel = pangolin.CreatePanel('menu') panel.SetBounds(1.0, 1.0, 0.0, 100 / 640.) # Does not work with initialization of window # self.Init() camera_pose = pangolin.OpenGlMatrix() # create scene graph # scene = pangolin.Renderable() # # x : R # # y : G # # z : B # scene.Add(pangolin.Axis()) # rendered_cam = pangolin.OpenGlRenderState( pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.01, 2000), pangolin.ModelViewLookAt(1, 0, 1, 0, 0, 0, 0, 0, 1) ) handler = pangolin.Handler3D(rendered_cam) # handler = pangolin.SceneHandler(scene, rendered_cam) # add drawing callback # viewport = pangolin.CreateDisplay() viewport.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0 / 480.0) viewport.SetHandler(handler) image_viewport = pangolin.Display('image') w = 160 h = 120 image_viewport.SetBounds(0, h / 480., 0.0, w / 640., 640. / 480.) image_viewport.SetLock(pangolin.Lock.LockLeft, pangolin.Lock.LockTop) texture = pangolin.GlTexture(w, h, gl.GL_RGB, False, 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) # geometries self.lines = [] self.points = {} self.colors = {} self.poses = [] self.redundant_points = [] self.redundant_colors = [] self.landmarks = {} # img = np.ones((h, w, 3), 'uint8') while not pangolin.ShouldQuit(): datum = None if not self.attributes.empty(): self.logger.info("[GL Process] attributes is not empty, fetching datum ...") datum = self.attributes.get() self.logger.info("[GL Process] get a datum from the main thread of the parent process") if datum is not None: # dispatch instructions if datum.attrs.get('pose', None) is not None: pose = datum.attrs['pose'] # self.camera.pose.m = pose # set Twc camera_pose.m = pose # np.linalg.inv(pose) # camera_pose.m = pose rendered_cam.Follow(camera_pose, True) self.logger.info("[GL Process] update camera pose matrix got from datum: \n%s" % pose) pass pass # self.Clear() # self.control.Update(self.camera.pose) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) viewport.Activate(rendered_cam) # scene.Render() # Just for test # pangolin.glDrawColouredCube(0.1) # render graph if datum is not None: # dispatch data # update graph if datum.attrs.get('lines', None) is not None: lines = datum.attrs['lines'] self.lines.extend(lines) self.logger.info("[GL Process] drawing %d lines ..." % len(lines)) if datum.attrs.get('pose', None) is not None: pose = datum.attrs['pose'] self.poses.append(pose) self.logger.info("[GL Process] drawing a camera with new pose matrix ...") pass # update image if datum.attrs.get('img', None) is not None: img = datum.attrs['img'] # see pangolin issue #180 # change cv BGR channels to norm one # img = img[::-1, : ,::-1].astype(np.uint8) img = img.astype(np.uint8) img = cv2.resize(img, (w, h)) self.logger.info("[GL Process] drawing image to image viewport ...") # show mappoints if datum.attrs.get('points', None) is not None: points = datum.attrs['points'] if len(points) > 0: # self.points.extend(points) for point in points: self.points[point.seq] = point # colors = np.array([p.color if p.color is not None else np.array([1.0, 0.0, 0.0]) for p in points]).astype(np.float64) colors = [p.color / 255. if p.color is not None else np.array([1.0, 1.0, 0.0]) for p in points] # print("colors: \n%s" % np.array(colors)) # colors = [ [1., 1., 0.] for p in points] # self.colors.extend(colors) for i, color in enumerate(colors): point = points[i] self.colors[point.seq] = color self.logger.info("[GL Process] drawing %d points" % len(points)) # print("new mappoints: \n%s" % np.array([ p.data for p in points]).astype(np.float64)) # print("new colors (default): \n%s" % np.array(colors)) else: self.logger.info("[GL Process] no points to be drawn.") # redundant points if datum.attrs.get('points-redundant', None) is not None: points = datum.attrs['points-redundant'] colors = datum.attrs['colors-redundant'] for i, p in enumerate(points): self.redundant_points.append(p) self.redundant_colors.append(colors[i] / 255.) # show landmarks if datum.attrs.get('landmarks', None) is not None: landmarks = datum.attrs['landmarks'] for landmark in landmarks: self.landmarks[landmark.seq] = landmark self.logger.info("[GL Process] drawing %d landmarks" % len(landmarks)) self.attributes.task_done() self.logger.info("[GL Process] datum has been processed.") ############ # draw graph ############ line_geometries = np.array([ [*line[0], *line[1]] for line in self.lines ]) if len(line_geometries) > 0: gl.glLineWidth(1) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawLines(line_geometries, 3) # pose = self.camera.pose pose = camera_pose # GL 2.0 API gl.glPointSize(4) gl.glColor3f(1.0, 0.0, 0.0) gl.glBegin(gl.GL_POINTS) gl.glVertex3d(pose[0, 1], pose[1, 3], pose[2, 3]) gl.glEnd() ############ # draw poses ############ if len(self.poses) > 0: gl.glLineWidth(1) gl.glColor3f(0.0, 0.0, 1.0) # poses: numpy.ndarray[float64], w: float=1.0, h_ratio: float=0.75, z_ratio: float=0.6 pangolin.DrawCameras(np.array(self.poses)) gl.glPointSize(4) gl.glColor3f(0.0, 0.0, 1.0) gl.glBegin(gl.GL_POINTS) for pose in self.poses: gl.glVertex3d(pose[0, 1], pose[1, 3], pose[2, 3]) gl.glEnd() ################ # draw mappoints ################ if len(self.points) > 0: # points_geometries = np.array([p.data for p in self.points]).astype(np.float64) points_geometries = [] colors = [] for point_key, p in self.points.items(): points_geometries.append(p.data) colors.append(self.colors[point_key]) points_geometries = np.array(points_geometries).astype(np.float64) colors = np.array(colors).astype(np.float64) gl.glPointSize(6) # pangolin.DrawPoints(points_geometries, np.array(self.colors).astype(np.float64) ) pangolin.DrawPoints(points_geometries, colors) # gl.glPointSize(4) # gl.glColor3f(1.0, 0.0, 0.0) # # gl.glBegin(gl.GL_POINTS) # for point in points_geometries: # gl.glVertex3d(point[0], point[1], point[2]) # gl.glEnd() #################### # redundant points # #################### if len(self.redundant_points) > 0: points_geometries = [] colors = [] for i, p in enumerate(self.redundant_points): points_geometries.append(p.data) colors.append(self.redundant_colors[i]) points_geometries = np.array(points_geometries).astype(np.float64) colors = np.array(colors).astype(np.float64) gl.glPointSize(3) pangolin.DrawPoints(points_geometries, colors) ################ # draw landmarks ################ for key, landmarkDatum in self.landmarks.items(): # abox = landmark.computeAABB() # drawABox(abox.toArray()) drawABox(landmarkDatum.abox.toArray(), color=landmarkDatum.color) pass ############# # draw images ############# # self.camera.RenderImg(img) texture.Upload(img, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) image_viewport.Activate() gl.glColor3f(1.0, 1.0, 1.0) texture.RenderToViewport() pangolin.FinishFrame() print("gl program loop stopped") with self._state_locker: self._stopped = True
def view(self): pangolin.CreateWindowAndBind('Viewer', 1024, 768) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) panel = pangolin.CreatePanel('menu') panel.SetBounds(0.5, 1.0, 0.0, 175 / 1024.) # checkbox if self.view_point_cloud: m_show_points = pangolin.VarBool('menu.Show Points', True, True) m_show_keyframes = pangolin.VarBool('menu.Show KeyFrames', True, True) m_show_graph = pangolin.VarBool('menu.Show Graph', True, True) m_show_image = pangolin.VarBool('menu.Show Image', True, True) # button m_next_frame = pangolin.VarBool('menu.Next', False, False) if self.config is None: viewpoint_x = 0 viewpoint_y = -500 # -10 viewpoint_z = -100 # -0.1 viewpoint_f = 2000 camera_width = 1. width, height = 350, 250 else: viewpoint_x = self.config.view_viewpoint_x viewpoint_y = self.config.view_viewpoint_y viewpoint_z = self.config.view_viewpoint_z viewpoint_f = self.config.view_viewpoint_f camera_width = self.config.view_camera_width width = self.config.view_image_width * 2 height = self.config.view_image_height proj = pangolin.ProjectionMatrix(1024, 768, viewpoint_f, viewpoint_f, 512, 389, 0.1, 5000) look_view = pangolin.ModelViewLookAt(viewpoint_x, viewpoint_y, viewpoint_z, 0, 0, 0, 0, -1, 0) # Camera Render Object (for view / scene browsing) scam = pangolin.OpenGlRenderState(proj, look_view) # Add named OpenGL viewport to window and provide 3D Handler dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 175 / 1024., 1.0, -1024 / 768.) dcam.SetHandler(pangolin.Handler3D(scam)) # Dilay image dimg = pangolin.Display('image') dimg.SetBounds(0, height / 768., 0.0, width / 1024., 1024 / 768.) dimg.SetLock(pangolin.Lock.LockLeft, pangolin.Lock.LockTop) texture = pangolin.GlTexture(width, height, gl.GL_RGB, False, 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) image = np.ones((height, width, 3), 'uint8') pose = pangolin.OpenGlMatrix() # identity matrix active = [] graph = [] loops = [] loops_local = [] mappoints = DynamicArray(shape=(3, )) colors = DynamicArray(shape=(3, )) cameras = DynamicArray(shape=(4, 4)) while not pangolin.ShouldQuit(): if not self.q_pose.empty(): pose.m = self.q_pose.get() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) dcam.Activate(scam) # Show graph if not self.q_graph.empty(): graph = self.q_graph.get() loops = np.array([_[0] for _ in graph if _[1] == 2]) loops_local = np.array([_[0] for _ in graph if _[1] == 1]) graph = np.array([_[0] for _ in graph if _[1] == 0]) if m_show_graph.Get(): if len(graph) > 0: gl.glLineWidth(1) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawLines(graph, 3) if len(loops) > 0: gl.glLineWidth(2) gl.glColor3f(1.0, 0.0, 1.0) pangolin.DrawLines(loops, 4) if len(loops_local) > 0: gl.glLineWidth(2) gl.glColor3f(1.0, 1.0, 0.0) pangolin.DrawLines(loops_local, 4) if self.view_point_cloud: # Show mappoints if not self.q_points.empty(): pts, code = self.q_points.get() cls, code = self.q_colors.get() if code == 1: # append new points mappoints.extend(pts) colors.extend(cls) elif code == 0: # refresh all points mappoints.clear() mappoints.extend(pts) colors.clear() colors.extend(cls) if m_show_points.Get(): gl.glPointSize(2) # easily draw millions of points pangolin.DrawPoints(mappoints.array(), colors.array()) if not self.q_active.empty(): active = self.q_active.get() gl.glPointSize(3) gl.glBegin(gl.GL_POINTS) gl.glColor3f(1.0, 0.0, 0.0) for point in active: gl.glVertex3f(*point) gl.glEnd() # Show cameras if not self.q_camera.empty(): cams = self.q_camera.get() if len(cams) > 20: cameras.clear() cameras.extend(cams) if m_show_keyframes.Get(): if cameras.array().shape[0] > 0: gl.glLineWidth(1) gl.glColor3f(0.0, 0.0, 1.0) pangolin.DrawCameras(cameras.array()[:-1], camera_width) gl.glLineWidth(1) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawCameras( np.expand_dims(cameras.array()[-1], axis=0), camera_width) # Show image if not self.q_image.empty(): image = self.q_image.get() if image.ndim == 3: image = image[::-1, :, ::-1] else: image = np.repeat(image[::-1, :, np.newaxis], 3, axis=2) image = cv2.resize(image, (width, height)) if m_show_image.Get(): texture.Upload(image, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) dimg.Activate() gl.glColor3f(1.0, 1.0, 1.0) texture.RenderToViewport() if pangolin.Pushed(m_next_frame): self.q_next.put(True) pangolin.FinishFrame()
def draw_cameras(self, Ts, color=(0.0, 0.0, 1.0)): self.dcam.Activate(self.scam) gl.glLineWidth(1) gl.glColor3f(*color) pango.DrawCameras(Ts, h_ratio=0.31, z_ratio=0.5)
def viewer_refresh(self, q_poses, q_gt, q_img, q_errors, q_poses_optimized): while not q_poses.empty(): self.state = q_poses.get() if True: while not q_poses_optimized.empty(): self.state_optimized = q_poses_optimized.get() if not q_img.empty(): self.img = q_img.get() self.img = self.img[::-1, :] self.img = cv2.resize(self.img, (self.w_i, self.h_i)) while not q_gt.empty(): self.state_gt = q_gt.get() while not q_errors.empty(): error_r, error_t = q_errors.get()[-1] #self.log.Log(errors[0], errors[1], errors[2]) self.errorlog_t.append(error_t) self.errorlog_r.append(error_r) #print(np.shape(self.errorlog)) self.log.Log(np.sum(self.errorlog_t), np.sum(self.errorlog_r)) # Clear and Activate Screen (we got a real nice shade of gray gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.15, 0.15, 0.15, 0.0) #gl.glClearColor(0.0,0.0, 0.0, 0.0) self.dcam.Activate(self.scam) # Render if self.state is not None: gl.glLineWidth(1) # Render current pose if self.state_gt[0].shape[0] >= 1: gl.glColor3f(1.0, 1.0, 1.0) pangolin.DrawCameras(self.state_gt[1:]) # Render previous keyframes if self.state[0].shape[0] >= 2: gl.glColor3f(1.0, 0.0, 1.0) pangolin.DrawCameras(self.state[:-1]) # Render current pose if self.state[0].shape[0] >= 1: gl.glColor3f(0.2, 1.0, 0.2) pangolin.DrawCameras(self.state[-1:]) if True: if self.state_optimized is not None: if self.state_optimized[0].shape[0] >= 1: gl.glColor3f(0.5, 1.0, 1.0) pangolin.DrawCameras(self.state_optimized) #print(self.img.shape) #cv2.imshow("test", self.img) self.texture.Upload(self.img, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) self.dimg.Activate() gl.glColor3f(1.0, 1.0, 1.0) self.texture.RenderToViewport() pangolin.FinishFrame()
def view(self): pangolin.CreateWindowAndBind('Viewer', 1024, 768) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) viewpoint_x = 0 viewpoint_y = -5 # -10 viewpoint_z = -10 # -0.1 viewpoint_f = 200 camera_width = 0.5 proj = pangolin.ProjectionMatrix(1024, 768, viewpoint_f, viewpoint_f, 512, 389, 0.1, 5000) look_view = pangolin.ModelViewLookAt(viewpoint_x, viewpoint_y, viewpoint_z, 0, 0, 0, 0, -1, 0) scam = pangolin.OpenGlRenderState(proj, look_view) dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -1024. / 768.) dcam.SetHandler(pangolin.Handler3D(scam)) dimg = pangolin.Display('image') dimg.SetBounds(0.0, self.h / 768., 0.0, self.w / 1024., float(self.w) / self.h) dimg.SetLock(pangolin.Lock.LockLeft, pangolin.Lock.LockTop) texture = pangolin.GlTexture(self.w, self.h, gl.GL_RGB, False, 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) ddepth = pangolin.Display('depth') ddepth.SetBounds(self.h / 768., self.h / 768. * 2.0, 0.0, self.w / 1024., float(self.w) / float(self.h)) ddepth.SetLock(pangolin.Lock.LockLeft, pangolin.Lock.LockTop) if self.use_custom_depth_image: print("Use RGB depth buffer") texture_depth = pangolin.GlTexture(self.w, self.h, gl.GL_RGB, False, 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) else: texture_depth = pangolin.GlTexture(self.w, self.h, gl.GL_LUMINANCE, False, 0, gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE) cameras = [] trajectory = [] pose = pangolin.OpenGlMatrix() points = np.empty(shape=(0, 3)) colors = np.empty(shape=(0, 3)) # image = random_image(self.w, self.h) image = 255 * np.ones((self.h, self.w, 3), 'uint8') if self.use_custom_depth_image: depth = 255 * np.ones((self.h, self.w, 3), 'uint8') else: depth = 255 * np.ones((self.h, self.w), 'uint8') gl.glPointSize(3) gl.glLineWidth(2) while not pangolin.ShouldQuit(): if not self.q_camera.empty(): cameras = self.q_camera.get() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.75, 0.75, 0.75, 1.0) if not self.q_pose.empty(): pose.m = self.q_pose.get() # scam.Follow(pose, True) dcam.Activate(scam) gl.glColor3f(0.0, 0.0, 1.0) if len(cameras) > 0: pangolin.DrawCameras(cameras, camera_width) if not self.q_trajectory.empty(): trajectory = self.q_trajectory.get() if len(trajectory) > 1: gl.glColor3f(0.0, 0.0, 0.0) pangolin.DrawLine(trajectory) if not self.q_point.empty(): points = self.q_point.get() if not self.q_color.empty(): colors = self.q_color.get() # if len(points) > 0: # pangolin.DrawPoints(points, colors) if not self.q_image.empty(): image = self.q_image.get() # print(image.shape, image.dtype) texture.Upload(image, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) dimg.Activate() gl.glColor3f(1.0, 1.0, 1.0) texture.RenderToViewport() if not self.q_depth.empty(): depth = self.q_depth.get() print('^^^') print(depth.shape, depth.dtype) if self.use_custom_depth_image: texture_depth.Upload(depth, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) else: texture_depth.Upload(depth, gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE) ddepth.Activate() gl.glColor3f(1.0, 1.0, 1.0) texture_depth.RenderToViewport() pangolin.FinishFrame()
def viewer_refresh(self, qmap, qvo, is_paused): while not qmap.empty(): self.map_state = qmap.get() while not qvo.empty(): self.vo_state = qvo.get() # if pangolin.Pushed(self.button): # print('You Pushed a button!') self.do_follow = self.checkboxFollow.Get() self.is_grid = self.checkboxGrid.Get() self.draw_cameras = self.checkboxCams.Get() self.draw_covisibility = self.checkboxCovisibility.Get() self.draw_spanning_tree = self.checkboxSpanningTree.Get() #if pangolin.Pushed(self.checkboxPause): if self.checkboxPause.Get(): is_paused.value = 0 else: is_paused.value = 1 # self.int_slider.SetVal(int(self.float_slider)) self.pointSize = self.int_slider.Get() if self.do_follow and self.is_following: self.scam.Follow(self.Twc, True) elif self.do_follow and not self.is_following: self.scam.SetModelViewMatrix(self.look_view) self.scam.Follow(self.Twc, True) self.is_following = True elif not self.do_follow and self.is_following: self.is_following = False gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) self.dcam.Activate(self.scam) if self.is_grid: Viewer3D.drawPlane() # ============================== # draw map if self.map_state is not None: if self.map_state.cur_pose is not None: # draw current pose in blue gl.glColor3f(0.0, 0.0, 1.0) gl.glLineWidth(2) pangolin.DrawCamera(self.map_state.cur_pose) gl.glLineWidth(1) self.updateTwc(self.map_state.cur_pose) if self.map_state.predicted_pose is not None and kDrawCameraPrediction: # draw predicted pose in red gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawCamera(self.map_state.predicted_pose) if len(self.map_state.poses) > 1: # draw keyframe poses in green if self.draw_cameras: gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.map_state.poses[:]) # rysowaine wektora za którym powinno wyznaczać boxy if len(self.map_state.line) > 0: # # wyznaczam nowy wektor obrócony o -90 i 90 stopni o długości 10 gl.glLineWidth(3) gl.glPointSize(self.pointSize) gl.glColor3f(0.0, 0.0, 0.0) pangolin.DrawPoints(self.map_state.line) # # pangolin.DrawLines([self.map_state.line[0], self.map_state.line[0]]) if len(self.map_state.points) > 0: # draw keypoints with their color gl.glPointSize(self.pointSize) #gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(self.map_state.points, self.map_state.colors) # TODO dopisać rozwiązanie drukujące na ekran zaznaczone obiekty w postaci obszarów if len(self.map_state.dict_pose) > 0: for k, v in self.map_state.dict_pose.items(): sizes = [] poses = [np.identity(4) for i in range(len(v))] for pose, point in zip(poses, v): pose[:3, 3] = np.array(point[0]) sizes.append(np.array(point[1])) gl.glLineWidth(2) d_color = k[1:-1].split(' ') gl.glColor3f(float(d_color[0]), float(d_color[1]), float(d_color[2])) # gl.glColor3f(1.0, 0.0, 1.0) # gl.glColor3f(self.map_state.box_color) # print("{} {}".format(poses, sizes)) pangolin.DrawBoxes(poses, sizes) # pangolin.DrawBoxes(self.map_state.box_left_botton, self.map_state.box_size) if self.map_state.reference_pose is not None and kDrawReferenceCamera: # draw predicted pose in purple gl.glColor3f(0.5, 0.0, 0.5) gl.glLineWidth(2) pangolin.DrawCamera(self.map_state.reference_pose) gl.glLineWidth(1) if len(self.map_state.covisibility_graph) > 0: if self.draw_covisibility: gl.glLineWidth(1) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawLines(self.map_state.covisibility_graph, 3) if len(self.map_state.spanning_tree) > 0: if self.draw_spanning_tree: gl.glLineWidth(1) gl.glColor3f(0.0, 0.0, 1.0) pangolin.DrawLines(self.map_state.spanning_tree, 3) if len(self.map_state.loops) > 0: if self.draw_spanning_tree: gl.glLineWidth(2) gl.glColor3f(0.5, 0.0, 0.5) pangolin.DrawLines(self.map_state.loops, 3) gl.glLineWidth(1) # ============================== # draw vo if self.vo_state is not None: if self.vo_state.poses.shape[0] >= 2: # draw poses in green if self.draw_cameras: gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.vo_state.poses[:-1]) if self.vo_state.poses.shape[0] >= 1: # draw current pose in blue gl.glColor3f(0.0, 0.0, 1.0) current_pose = self.vo_state.poses[-1:] pangolin.DrawCameras(current_pose) self.updateTwc(current_pose[0]) if self.vo_state.traj3d_est.shape[0] != 0: # draw blue estimated trajectory gl.glPointSize(self.pointSize) gl.glColor3f(0.0, 0.0, 1.0) pangolin.DrawLine(self.vo_state.traj3d_est) if self.vo_state.traj3d_gt.shape[0] != 0: # draw red ground-truth trajectory gl.glPointSize(self.pointSize) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawLine(self.vo_state.traj3d_gt) pangolin.FinishFrame()
def viewer_refresh(self, qmap, qvo, is_paused): while not qmap.empty(): self.map_state = qmap.get() while not qvo.empty(): self.vo_state = qvo.get() # if pangolin.Pushed(self.button): # print('You Pushed a button!') self.do_follow = self.checkboxFollow.Get() self.is_grid = self.checkboxGrid.Get() self.draw_cameras = self.checkboxCams.Get() self.draw_covisibility = self.checkboxCovisibility.Get() self.draw_spanning_tree = self.checkboxSpanningTree.Get() #if pangolin.Pushed(self.checkboxPause): if self.checkboxPause.Get(): is_paused.value = 0 else: is_paused.value = 1 # self.int_slider.SetVal(int(self.float_slider)) self.pointSize = self.int_slider.Get() if self.do_follow and self.is_following: self.scam.Follow(self.Twc, True) elif self.do_follow and not self.is_following: self.scam.SetModelViewMatrix(self.look_view) self.scam.Follow(self.Twc, True) self.is_following = True elif not self.do_follow and self.is_following: self.is_following = False gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) self.dcam.Activate(self.scam) if self.is_grid: Viewer3D.drawPlane() # ============================== # draw map if self.map_state is not None: if self.map_state.cur_pose is not None: # draw current pose in blue gl.glColor3f(0.0, 0.0, 1.0) gl.glLineWidth(2) pangolin.DrawCamera(self.map_state.cur_pose) gl.glLineWidth(1) self.updateTwc(self.map_state.cur_pose) if self.map_state.predicted_pose is not None and kDrawCameraPrediction: # draw predicted pose in red gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawCamera(self.map_state.predicted_pose) if len(self.map_state.poses) >1: # draw keyframe poses in green if self.draw_cameras: gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.map_state.poses[:]) if len(self.map_state.points)>0: # draw keypoints with their color gl.glPointSize(self.pointSize) #gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(self.map_state.points, self.map_state.colors) if self.map_state.reference_pose is not None and kDrawReferenceCamera: # draw predicted pose in purple gl.glColor3f(0.5, 0.0, 0.5) gl.glLineWidth(2) pangolin.DrawCamera(self.map_state.reference_pose) gl.glLineWidth(1) if len(self.map_state.covisibility_graph)>0: if self.draw_covisibility: gl.glLineWidth(1) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawLines(self.map_state.covisibility_graph,3) if len(self.map_state.spanning_tree)>0: if self.draw_spanning_tree: gl.glLineWidth(1) gl.glColor3f(0.0, 0.0, 1.0) pangolin.DrawLines(self.map_state.spanning_tree,3) if len(self.map_state.loops)>0: if self.draw_spanning_tree: gl.glLineWidth(2) gl.glColor3f(0.5, 0.0, 0.5) pangolin.DrawLines(self.map_state.loops,3) gl.glLineWidth(1) # ============================== # draw vo if self.vo_state is not None: if self.vo_state.poses.shape[0] >= 2: # draw poses in green if self.draw_cameras: gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.vo_state.poses[:-1]) if self.vo_state.poses.shape[0] >= 1: # draw current pose in blue gl.glColor3f(0.0, 0.0, 1.0) current_pose = self.vo_state.poses[-1:] pangolin.DrawCameras(current_pose) self.updateTwc(current_pose[0]) if self.vo_state.traj3d_est.shape[0] != 0: # draw blue estimated trajectory gl.glPointSize(self.pointSize) gl.glColor3f(0.0, 0.0, 1.0) pangolin.DrawLine(self.vo_state.traj3d_est) if self.vo_state.traj3d_gt.shape[0] != 0: # draw red ground-truth trajectory gl.glPointSize(self.pointSize) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawLine(self.vo_state.traj3d_gt) pangolin.FinishFrame()
gl.glEnable(gl.GL_DEPTH_TEST) scam = pangolin.OpenGlRenderState( pangolin.ProjectionMatrix(w, h, 420, 420, w // 2, h // 2, 0.2, 10000), pangolin.ModelViewLookAt(0, -10, -8, 0, 0, 0, 0, -1, 0)) handler = pangolin.Handler3D(scam) # Create Interactive View in window dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 0.0, 1.0, w / h) dcam.SetHandler(handler) # hack to avoid small Pangolin, no idea why it's *2 dcam.Resize(pangolin.Viewport(0, 0, w * 2, h * 2)) dcam.Activate() while not pangolin.ShouldQuit(): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.0, 0.0, 0.0, 1.0) dcam.Activate(scam) if state is not None: if state[0].shape[0] >= 2: gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(state[0][:-1]) if state[0].shape[0] >= 1: gl.glColor3f(1.0, 1.0, 0.0) pangolin.DrawCameras(state[0][-1:]) # if state[1].shape[0] != 0: # gl.glPointSize(1) # gl.glColor3f(1.0, 0.0, 0.0) # pangolin.DrawPoints(state[1], state[2]) pangolin.FinishFrame()
def view(self): pangolin.CreateWindowAndBind('Viewer', 1024, 768) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) viewpoint_x = 0 viewpoint_y = -7 viewpoint_z = -18 viewpoint_f = 1000 proj = pangolin.ProjectionMatrix(1024, 768, viewpoint_f, viewpoint_f, 512, 389, 0.1, 300) look_view = pangolin.ModelViewLookAt(viewpoint_x, viewpoint_y, viewpoint_z, 0, 0, 0, 0, -1, 0) # Camera Render Object (for view / scene browsing) scam = pangolin.OpenGlRenderState(proj, look_view) # Add named OpenGL viewport to window and provide 3D Handler dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 175 / 1024., 1.0, -1024 / 768.) dcam.SetHandler(pangolin.Handler3D(scam)) # image width, height = 376, 240 dimg = pangolin.Display('image') dimg.SetBounds(0, height / 768., 0.0, width / 1024., 1024 / 768.) dimg.SetLock(pangolin.Lock.LockLeft, pangolin.Lock.LockTop) texture = pangolin.GlTexture(width, height, gl.GL_RGB, False, 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) image = np.ones((height, width, 3), 'uint8') # axis axis = pangolin.Renderable() axis.Add(pangolin.Axis()) trajectory = DynamicArray() camera = None image = None while not pangolin.ShouldQuit(): if not self.pose_queue.empty(): while not self.pose_queue.empty(): pose = self.pose_queue.get() trajectory.append(pose[:3, 3]) camera = pose if not self.image_queue.empty(): while not self.image_queue.empty(): img = self.image_queue.get() img = img[::-1, :, ::-1] img = cv2.resize(img, (width, height)) image = img.copy() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) dcam.Activate(scam) # draw axis axis.Render() # draw current camera if camera is not None: gl.glLineWidth(1) gl.glColor3f(0.0, 0.0, 1.0) pangolin.DrawCameras(np.array([camera]), 0.5) # show trajectory if len(trajectory) > 0: gl.glPointSize(2) gl.glColor3f(0.0, 0.0, 0.0) pangolin.DrawPoints(trajectory.array()) # show image if image is not None: texture.Upload(image, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) dimg.Activate() gl.glColor3f(1.0, 1.0, 1.0) texture.RenderToViewport() pangolin.FinishFrame()
def viewer_refresh(self, qmap, qvo): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) while not qmap.empty(): self.state_map = qmap.get() while not qvo.empty(): self.state_vo = qvo.get() # if pangolin.Pushed(self.button): # print('You Pushed a button!') self.do_follow = self.checkboxFollow.Get() self.is_grid = self.checkboxGrid.Get() self.draw_cameras = self.checkboxCams.Get() # self.int_slider.SetVal(int(self.float_slider)) self.pointSize = self.int_slider.Get() self.dcam.Activate(self.scam) if self.do_follow: self.scam.Follow(self.Twc, True) if self.is_grid: Viewer3D.drawPlane() # draw map if self.state_map is not None: if self.state_map[0].shape[0] >= 2: # draw poses in green if self.draw_cameras: gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.state_map[0][:-1]) if self.state_map[0].shape[0] >= 1: # draw current pose in blue gl.glColor3f(0.0, 0.0, 1.0) currentPose = self.state_map[0][-1:] pangolin.DrawCameras(currentPose) self.updateTwc(currentPose) if self.state_map[1].shape[0] != 0: # draw keypoints with their color gl.glPointSize(self.pointSize) #gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(self.state_map[1], self.state_map[2]) # draw vo if self.state_vo is not None: if self.state_vo[0].shape[0] >= 2: # draw poses in green if self.draw_cameras: gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.state_vo[0][:-1]) if self.state_vo[0].shape[0] >= 1: # draw current pose in blue gl.glColor3f(0.0, 0.0, 1.0) currentPose = self.state_vo[0][-1:] pangolin.DrawCameras(currentPose) self.updateTwc(currentPose) if self.state_vo[1].shape[0] != 0: # draw blue estimated trajectory gl.glPointSize(self.pointSize) gl.glColor3f(0.0, 0.0, 1.0) pangolin.DrawLine(self.state_vo[1]) if self.state_vo[2].shape[0] != 0: # draw red ground-truth trajectory gl.glPointSize(self.pointSize) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawLine(self.state_vo[2]) pangolin.FinishFrame()