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: gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.0, 0.0, 0.0, 0.0) self.dcam.Activate(self.scam) # Draw Point Cloud gl.glPointSize(2) gl.glColor3f(0.0, 1.0, 0.0) if self.history: self.points.append(state[0]) pangolin.DrawPoints( np.reshape(np.array(self.points), (-1, 3))) else: pangolin.DrawPoints(state[0]) pangolin.FinishFrame() except: continue
def main(): pango.CreateWindowAndBind('point cloud cube render', 640, 480) # Projection and ModelView Matrices scam = pango.OpenGlRenderState( pango.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.2, 100), pango.ModelViewLookAt(-1, -1, -1, 0, 0, 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 a random point cloud pts = np.random.random((100, 3)) * 10 # Color matrix based on point location colors = np.zeros((len(pts), 3)) colors[:, :] = 1. - pts[:, :] / 10 #colors[:] = [1.0, 0.0, 0.0] 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) # Draw Points gl.glPointSize(5) gl.glColor3f(0.0, 1.0, 0.0) pango.DrawPoints(pts, colors) # Finish Drawing pango.FinishFrame()
def main(): 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.AxisY)) tree = pangolin.Renderable() tree.Add(pangolin.Axis()) # Create Interactive View in window handler = pangolin.SceneHandler(tree, scam) dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0 / 480.0) dcam.SetHandler(handler) def draw(view): view.Activate(scam) tree.Render() dcam.SetDrawFunction(draw) while not pangolin.ShouldQuit(): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # or # dcam.Activate(scam) # tree.Render() pangolin.FinishFrame()
def main(): 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, 200), 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) while not pangolin.ShouldQuit(): 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 Point Cloud points = np.random.random((10000, 3)) colors = np.zeros((len(points), 3)) colors[:, 1] = 1 - points[:, 0] colors[:, 2] = 1 - points[:, 1] colors[:, 0] = 1 - points[:, 2] points = points * 3 + 1 gl.glPointSize(5) pangolin.DrawPoints(points, colors) pangolin.FinishFrame()
def DISPLAY(): import numpy as np 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)) 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) while not pangolin.ShouldQuit(): 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() # Draw Point Cloud points = np.random.random((100000, 3)) * 10 gl.glPointSize(2) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(points) pangolin.FinishFrame()
def visualize_3D(p3D): pangolin.CreateWindowAndBind('main', 640, 480) gl.glEnable(gl.GL_DEPTH_TEST) 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)) handler = pangolin.Handler3D(scam) dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0 / 480.0) dcam.SetHandler(handler) while not pangolin.ShouldQuit(): 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) #gl.glPointSize(5); #gl.glColor3f(0.0,0.0,1.0); #pangolin.DrawPoints(p3D); # Attempt to draw camera gl.glLineWidth(2) gl.glColor3f(1.0, 0.0, 0.0) #pose = np.identity(4); pose = (np.hstack((pose1.T, np.zeros((4, 1))))).T pangolin.DrawCamera(pose, 0.5, 0.75, 0.8) pangolin.FinishFrame()
def main(showSemSegmentation=False): # create window 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, 50), pangolin.ModelViewLookAt(0, 0, -.01, 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, colors, sem = getPointsAndColors("000020.png") # If we want to show the semantic segmentations if showSemSegmentation: colors = colors * 0.5 + sem * 0.5 while not pangolin.ShouldQuit(): 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) gl.glPointSize(2) gl.glColor3f(1.0, 0.0, 0.0) # access numpy array directly(without copying data), array should be contiguous. pangolin.DrawPoints(points, colors) pangolin.FinishFrame()
def step_fn(step, inputs): # Forward pass and loss with torch.no_grad(): loss, data = utils.forward_pass(model, loss_fn, inputs) print("loss %f" % loss.item()) print(data.keys()) print(data["pose"].shape) for i in range(args.batch): print(list(data["pose"][i, 0, :].cpu().detach().numpy())) print(list(data["pose"][i, 1, :].cpu().detach().numpy())) print("--") depth_img = viz.tensor2depthimg( torch.cat((*data["depth"][0][:, 0], ), dim=0)) tgt_img = viz.tensor2img(torch.cat((*data["tgt"], ), dim=1)) img = np.concatenate((tgt_img, depth_img), axis=1) warp_imgs = [] #diff_imgs = [] for warp, diff in zip(data["warp"], data["diff"]): warp = restack(restack(warp, 1, -1), 0, -2) diff = restack(restack(diff, 1, -1), 0, -2) warp_imgs.append(viz.tensor2img(warp)) #diff_imgs.append(viz.tensor2diffimg(diff)) world = reconstruction.depth_to_3d_points(data["depth"][0], data["K"]) points = world[0, :].view(3, -1).transpose( 1, 0).cpu().detach().numpy().astype(np.float64) colors = (data["tgt"][0, :].view(3, -1).transpose( 1, 0).cpu().detach().numpy().astype(np.float64) + 1) / 2 loop = True while loop: key = cv2.waitKey(10) if key == 27 or pango.ShouldQuit(): exit() elif key != -1: loop = False cv2.imshow("target and depth", img) #for i, (warp, diff) in enumerate(zip(warp_imgs, diff_imgs)): for i, warp in enumerate(warp_imgs): cv2.imshow("warp scale: %d" % i, warp) #cv2.imshow("diff scale: %d" % i, diff) 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) gl.glPointSize(5) pango.DrawPoints(points, colors) pose = np.identity(4) pose[:3, 3] = 0 gl.glLineWidth(1) gl.glColor3f(0.0, 0.0, 1.0) pango.DrawCamera(pose, 0.5, 0.75, 0.8) pango.FinishFrame()
def __init__(self, graph): self.init() self.graph = graph self.nodes = np.dot(graph.nodes, self.tform) self.edges = np.array(graph.edges) while not pango.ShouldQuit(): self.refresh()
def main(): # Create OpenGL window in single line 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)) 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) # Data logger object log = pangolin.DataLog() # Optionally add named labels labels = ['sin(t)', 'cos(t)', 'sin(t)+cos(t)'] log.SetLabels(labels) # OpenGL 'view' of data. We might have many views of the same data. tinc = 0.03 plotter = pangolin.Plotter(log, 0.0, 6.0 * np.pi / tinc, -2.0, 2.0, np.pi / (6 * tinc), 0.5) plotter.SetBounds(0.05, 0.3, 0.0, 0.4) plotter.Track('$i') # Add some sample annotations to the plot plotter.AddMarker(pangolin.Marker.Vertical, -1000, pangolin.Marker.LessThan, pangolin.Colour.Blue().WithAlpha(0.2)) plotter.AddMarker(pangolin.Marker.Horizontal, 100, pangolin.Marker.GreaterThan, pangolin.Colour.Red().WithAlpha(0.2)) plotter.AddMarker(pangolin.Marker.Horizontal, 10, pangolin.Marker.Equal, pangolin.Colour.Green().WithAlpha(0.2)) pangolin.DisplayBase().AddDisplay(plotter) t = 0 while not pangolin.ShouldQuit(): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # Plot line log.Log(np.sin(t), np.cos(t), np.sin(t) + np.cos(t)) t += tinc gl.glClearColor(1.0, 1.0, 1.0, 1.0) dcam.Activate(scam) # Render OpenGL 3D Cube pangolin.glDrawColouredCube() pangolin.FinishFrame()
def viewer_thread(self, q_poses, q_gt, q_img, q_errors, q_poses_optimized): self.viewer_init() while not pangolin.ShouldQuit(): #True: #print('refresh') self.viewer_refresh(q_poses, q_gt, q_img, q_errors, q_poses_optimized) print("you hit quit") vt_done.set()
def t_draw2(self): trajectory = [[0, -6, 6]] for i in range(300): trajectory.append(trajectory[-1] + np.random.random(3) - 0.5) trajectory = np.array(trajectory) while not pangolin.ShouldQuit(): 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) # Render OpenGL Cube pangolin.glDrawColouredCube(0.1) # Draw Point Cloud points = np.random.random((10000, 3)) * 3 - 4 gl.glPointSize(1) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(points) # Draw Point Cloud points = np.random.random((10000, 3)) colors = np.zeros((len(points), 3)) colors[:, 1] = 1 - points[:, 0] colors[:, 2] = 1 - points[:, 1] colors[:, 0] = 1 - points[:, 2] points = points * 3 + 1 gl.glPointSize(1) pangolin.DrawPoints(points, colors) # Draw lines gl.glLineWidth(1) gl.glColor3f(0.0, 0.0, 0.0) pangolin.DrawLine(trajectory) # consecutive gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawLines(trajectory, trajectory + np.random.randn(len(trajectory), 3), point_size=5) # separate # Draw camera pose = np.identity(4) pose[:3, 3] = np.random.randn(3) gl.glLineWidth(1) gl.glColor3f(0.0, 0.0, 1.0) pangolin.DrawCamera(pose, 0.5, 0.75, 0.8) # Draw boxes poses = [np.identity(4) for i in range(10)] for pose in poses: pose[:3, 3] = np.random.randn(3) + np.array([5, -3, 0]) sizes = np.random.random((len(poses), 3)) gl.glLineWidth(1) gl.glColor3f(1.0, 0.0, 1.0) pangolin.DrawBoxes(poses, sizes) pangolin.FinishFrame()
def main(self): ''' Main function: Creates the user window and side bar with a button. This button is used to toggle between normal point cloud and downsampled point cloud ''' pangolin.CreateWindowAndBind('Sample Toggle App', 1280, 960) #Set sindow size and name gl.glEnable( gl.GL_DEPTH_TEST ) #This is enabled to allow for user to move/rotate 3D image with mouse #Define render object SampleToggling.scam = pangolin.OpenGlRenderState( pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.1, 1000), pangolin.ModelViewLookAt(0, 0.5, -3, 0, 0, 0, pangolin.AxisDirection.AxisY)) handler3d = pangolin.Handler3D(SampleToggling.scam) #Add viewpoint object SampleToggling.dcam = pangolin.CreateDisplay() SampleToggling.dcam.SetBounds(0.0, 1.0, 180 / 640., 1.0, -640.0 / 480.0) SampleToggling.dcam.SetHandler(pangolin.Handler3D(SampleToggling.scam)) #Create the side panel panel = pangolin.CreatePanel('buttonPanel') panel.SetBounds(0.0, 1.0, 0.0, 180 / 640.) gl.glPointSize(1) #Set the size of each point on the point cloud button = pangolin.VarBool('buttonPanel.Sampling Toggle Button', value=False, toggle=False) #Create a simple button #Read the .ply file and convert it into a numpy array so it can be understood by pangolin pointCloudOrigional = o3d.io.read_point_cloud("bunny.ply") pointCloudOrigionalArray = np.asarray(pointCloudOrigional.points) #Down sample this read .ply file and then convert that into a numpy array pointCloudDownSampled = voxel_down_sample(pointCloudOrigional, voxel_size=0.008) pointCloudDownSampledArray = np.asarray(pointCloudDownSampled.points) #Zoom the pointCloud so it is easy for user to see pointCloudOrigionalZoomed = pointCloudOrigionalArray * self.zoomCoefficient pointCloudSampledZoomed = pointCloudDownSampledArray * self.zoomCoefficient #Run a loop until the program is quit, toggling image each time button is pressed. while not pangolin.ShouldQuit(): self.drawPoints(pointCloudOrigionalZoomed) if pangolin.Pushed(button): while not pangolin.Pushed(button): self.drawPoints(pointCloudSampledZoomed)
def work(q, qclose, w=960, h=540): pangolin.CreateWindowAndBind('pangolin', w, h) gl.glEnable(gl.GL_DEPTH_TEST) # Define Projection and initial ModelView matrix scam = pangolin.OpenGlRenderState( pangolin.ProjectionMatrix(w, h, 420, 420, w // 2, h // 2, 0.2, 10000), pangolin.ModelViewLookAt(-2, -2, -8, 0, 0, 0, pangolin.AxisDirection.AxisNegY)) 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) pose = np.eye(4) opath = np.zeros((0, 3)) opts = np.zeros((2, 3)) colors = np.zeros((2, 3)) while not pangolin.ShouldQuit(): if not qclose.empty(): if qclose.get(): pangolin.Quit() if not q.empty(): pose, opath, opts, colors = q.get() colors /= 256.0 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) # draw_axes() # Draw optimized cloud gl.glPointSize(2) gl.glColor3f(0.5, 0.8, 0.5) pangolin.DrawPoints(opts, colors) # Draw camera gl.glLineWidth(1) gl.glColor3f(0.4, 0.4, 0.4) pangolin.DrawCamera(pose, 10, 1, 1) # Optimized path if len(opath) > 2: gl.glLineWidth(1) gl.glColor3f(0.4, 0.4, 0.4) pangolin.DrawLine(np.array(opath)) pangolin.FinishFrame()
def run(dq, name): pangolin.CreateWindowAndBind(name, 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, 2000), pangolin.ModelViewLookAt(-70, -70, 70, 0, 0, 0, pangolin.AxisDirection.AxisZ)) # Create Interactive View in window dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0 / 480.0) dcam.SetHandler(pangolin.Handler3D(scam)) should_quit = False handlers = { 'pts': VisualizerPangoV2.handler_pts, 'boxes_3d': VisualizerPangoV2.handler_bboxes3d, 'boxes_3d_center': VisualizerPangoV2.handler_bboxes3d_center, 'lines': VisualizerPangoV2.handler_lines, 'boxes_2d': VisualizerPangoV2.handler_bboxes2d } targets = {} for k in handlers: targets[k] = {} while not (pangolin.ShouldQuit() or should_quit): 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) pangolin.glDrawColouredCube() while not dq.empty(): o = dq.get() if type(o) is str: if o == 'quit': should_quit = True break if type(o) is tuple: op, tp, k, v = o if tp == 'cam': VisualizerPangoV2.handler_cam(scam, v) else: if op == 'reset': targets[tp][k] = [v] elif op == 'add': if k not in targets[tp]: targets[tp][k] = [] targets[tp][k].append(v) for t in handlers: for k in targets[t]: for v in targets[t][k]: handlers[t](*v) pangolin.FinishFrame()
def main(): # Create OpenGL window in single line pangolin.CreateWindowAndBind('Main', 640, 480) # 3D Mouse handler requires depth testing to be enabled gl.glEnable(gl.GL_DEPTH_TEST) scam = pangolin.OpenGlRenderState( pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.1, 1000), pangolin.ModelViewLookAt(-1, 1, -1, 0, 0, 0, pangolin.AxisDirection.AxisY)) # Aspect ratio allows us to constrain width and height whilst fitting within specified # bounds. A positive aspect ratio makes a view 'shrink to fit' (introducing empty bars), # whilst a negative ratio makes the view 'grow to fit' (cropping the view). dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0 / 480.0) dcam.SetHandler(pangolin.Handler3D(scam)) # This view will take up no more than a third of the windows width or height, and it # will have a fixed aspect ratio to match the image that it will display. When fitting # within the specified bounds, push to the top-left (as specified by SetLock). dimg = pangolin.Display('image') dimg.SetBounds(2. / 3, 1.0, 0.0, 1. / 3, 640. / 480) dimg.SetLock(pangolin.Lock.LockLeft, pangolin.Lock.LockTop) w, h = 64, 48 texture = pangolin.GlTexture(w, h, gl.GL_RGB, False, 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) # Default hooks for exiting (Esc) and fullscreen (tab). while not pangolin.ShouldQuit(): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.95, 0.95, 0.95, 1.0) dcam.Activate(scam) gl.glColor3f(1.0, 1.0, 1.0) pangolin.glDrawColouredCube() # Set some random image data and upload to GPU image = random_image(w, h) texture.Upload(image, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) # display the image dimg.Activate() gl.glColor3f(1.0, 1.0, 1.0) texture.RenderToViewport() pangolin.FinishFrame()
def run(self): pangolin.CreateWindowAndBind(self.win_name, 640, 480) gl.glEnable(gl.GL_DEPTH_TEST) self.scam = pangolin.OpenGlRenderState( pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.2, 1000), pangolin.ModelViewLookAt(2, -10, -30, 0, 0, 0, pangolin.AxisNegY)) self.tree = pangolin.Renderable() self.tree.Add(pangolin.Axis()) self.handler = pangolin.SceneHandler(self.tree, self.scam) self.dcam = pangolin.CreateDisplay() self.dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0 / 480.0) self.dcam.SetHandler(self.handler) while not pangolin.ShouldQuit(): 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) self.tree.Render() self.data_lock.acquire() if self.poses: gl.glPointSize(5) gl.glColor3f(*self.cam_color) for pose in self.poses: pangolin.DrawPoints(pose[1].T) if self.map_pts is not None: gl.glPointSize(2) gl.glColor3f(*self.map_pts_color) pangolin.DrawPoints(self.map_pts) if self.new_pts_obs is not None: cur_pos = self.poses[-1] cam_centers = np.repeat(cur_pos[1].T, self.new_pts_obs.shape[0], axis=0) gl.glLineWidth(1) gl.glColor3f(0.0, 0.0, 1.0) pangolin.DrawLines(cam_centers, self.new_pts_obs) self.data_lock.release() time.sleep(0.02) pangolin.FinishFrame()
def run_viewer(q): w, h = 1024, 768 f = 2000 pango.CreateWindowAndBind('g2o', w, h) gl.glEnable(gl.GL_DEPTH_TEST) cam = pango.OpenGlRenderState( pango.ProjectionMatrix(w, h, f, f, w // 2, h // 2, 0.1, 100000), pango.ModelViewLookAt( 1000., 1000., 1000., 0., 0., 0., 0., -1., 0., )) handler = pango.Handler3D(cam) dcam = pango.CreateDisplay() dcam.SetBounds(0., 1., 0., 1., -w / h) dcam.SetHandler(handler) dcam.Activate() # nodes = [x.estimate().matrix() for x in optimizer.vertices().values()] # nodes = np.array(nodes) edges = None while not pango.ShouldQuit(): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(0.15, 0.15, 0.15, 0.0) dcam.Activate(cam) try: edges = q.get(block=False) except queue.Empty: pass if edges is not None: gl.glLineWidth(1) gl.glColor3f(0.2, 1.0, 0.2) pango.DrawLines(edges[:, 0], edges[:, 1]) pango.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 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 draw(self, poseList_nx4x4, drawCamera=False): while not pangolin.ShouldQuit(): 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) # pangolin.glDrawColouredCube() # points = np.random.random((10000, 3)) *10 gl.glPointSize(2) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawLine(np.array([[0, 0, 0], [1.0, 0.0, 0.0]])) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawLine(np.array([[0, 0, 0], [0.0, 1.0, 0.0]])) gl.glColor3f(.0, 0.0, 1.0) pangolin.DrawLine(np.array([[0, 0, 0], [0.0, 0.0, 1.0]])) origin = [[0, 0, 0]] originHomo = h**o(np.zeros((3, 1))) originT = np.eye(4) # pangolin.Draw index = 0 for T in poseList_nx4x4: originT = originT.dot(T) if drawCamera: gl.glColor3f(0.5, 0.75, 0.8) pangolin.DrawCamera(originT) pAfter = originT.dot(originHomo) p = unHomo(pAfter) origin.append([p[0][0], p[1][0], p[2][0]]) # line if np.mod(index, 2) == 0: gl.glColor3f(0.0, 0.0, 0.0) else: gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawLine(origin) index += 1 # time.sleep(0.01) pangolin.FinishFrame()
def t_draw(self): while not pangolin.ShouldQuit(): 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) pangolin.glDrawColouredCube() # points = np.random.random((10000, 3)) *10 gl.glPointSize(2) gl.glColor3f(1.0, 0.0, 0.0) # pangolin.DrawPoints(points) for theta in np.arange(0, np.pi, np.pi / 10): for psi in np.arange(0, np.pi * 2, np.pi / 10): T = makeT(Y(theta).dot(Z(psi)), np.random.random((3, 1)) * 10) pangolin.DrawCamera(T) time.sleep(0.4) # pangolin.DrawCamera(np.eye(4)) pangolin.FinishFrame()
def cloud_for_vis(img,depth): index_matrix_2[:,2] = np.reshape(depth,(480*640)) points_in_cam_frame = index_matrix_2 #point_in_cam_frame = np.transpose(depth*index_matrix_2) # 3x480*640 points_in_world = np.matmul(camera_matrix_inv,points_in_cam_frame.T) # 3x480*640 points_in_world = np.transpose(points_in_world) # 480*640x3 points_colours = np.reshape(img,(480*640,3)) # RGB values for each point """fig = plt.figure() ax = Axes3D(fig) #ax.scatter([2,4,5,2],[3,4,2,1],[6,3,4,1]) ax.scatter(points_in_world[:,0],points_in_world[:,1],points_in_world[:,2]) plt.show()""" 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)) 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) while not pangolin.ShouldQuit(): 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() # Draw Point Cloud points = points_in_world#np.random.random((100000, 3)) * 10 gl.glPointSize(2) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(points) pangolin.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 main(): 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)) 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) dcam.Resize(pangolin.Viewport(0, 0, 640 * 2, 480 * 2)) while not pangolin.ShouldQuit(): 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() # Draw Point Cloud points = np.random.random((100000, 3)) * 10 colors = np.zeros((len(points), 3)) colors[:, 1] = 1 - points[:, 0] / 10. colors[:, 2] = 1 - points[:, 1] / 10. colors[:, 0] = 1 - points[:, 2] / 10. gl.glPointSize(2) gl.glColor3f(1.0, 0.0, 0.0) # access numpy array directly(without copying data), array should be contiguous. pangolin.DrawPoints(points, colors) pangolin.FinishFrame()
def main(): # Create OpenGL window in single line pangolin.CreateWindowAndBind('Main', 640, 480) # Data logger object log = pangolin.DataLog() # Optionally add named labels labels = ['sin(t)', 'cos(t)', 'sin(t)+cos(t)'] log.SetLabels(labels) # OpenGL 'view' of data. We might have many views of the same data. tinc = 0.03 plotter = pangolin.Plotter(log, 0.0, 4.0 * np.pi / tinc, -2.0, 2.0, np.pi / (4 * tinc), 0.5) plotter.SetBounds(0.0, 1.0, 0.0, 1.0) plotter.Track('$i') # Add some sample annotations to the plot plotter.AddMarker(pangolin.Marker.Vertical, -1000, pangolin.Marker.LessThan, pangolin.Colour.Blue().WithAlpha(0.2)) plotter.AddMarker(pangolin.Marker.Horizontal, 100, pangolin.Marker.GreaterThan, pangolin.Colour.Red().WithAlpha(0.2)) plotter.AddMarker(pangolin.Marker.Horizontal, 10, pangolin.Marker.Equal, pangolin.Colour.Green().WithAlpha(0.2)) pangolin.DisplayBase().AddDisplay(plotter) t = 0 while not pangolin.ShouldQuit(): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) log.Log(np.sin(t), np.cos(t), np.sin(t) + np.cos(t)) t += tinc 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 main(): 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, 200), 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) trajectory = [[0, -6, 6]] for i in range(300): trajectory.append(trajectory[-1] + np.random.random(3) - 0.5) trajectory = np.array(trajectory) while not pangolin.ShouldQuit(): 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(0.1) # Draw Point Cloud points = np.random.random((10000, 3)) * 3 - 4 gl.glPointSize(1) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(points) # Draw Point Cloud points = np.random.random((10000, 3)) colors = np.zeros((len(points), 3)) colors[:, 1] = 1 - points[:, 0] colors[:, 2] = 1 - points[:, 1] colors[:, 0] = 1 - points[:, 2] points = points * 3 + 1 print(points.shape) print(colors.shape) print(points[0:3]) print(colors[0:3]) gl.glPointSize(1) pangolin.DrawPoints(points, colors) # Draw lines gl.glLineWidth(1) gl.glColor3f(0.0, 0.0, 0.0) pangolin.DrawLine(trajectory) # consecutive gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawLines(trajectory, trajectory + np.random.randn(len(trajectory), 3), point_size=5) # separate # Draw camera pose = np.identity(4) pose[:3, 3] = np.ones(3) gl.glLineWidth(1) gl.glColor3f(0.0, 0.0, 1.0) pangolin.DrawCamera(pose, 0.5, 0.75, 0.8) # Draw boxes poses = [np.identity(4) for i in range(10)] for pose in poses: pose[:3, 3] = np.random.randn(3) + np.array([5, -3, 0]) sizes = np.random.random((len(poses), 3)) gl.glLineWidth(1) gl.glColor3f(1.0, 0.0, 1.0) pangolin.DrawBoxes(poses, sizes) pangolin.FinishFrame()
def should_quit(self): return pango.ShouldQuit()
def viewer_thread(self, qmap, qvo, is_running, is_paused): self.viewer_init(kViewportWidth, kViewportHeight) while not pangolin.ShouldQuit() and (is_running.value == 1): self.viewer_refresh(qmap, qvo, is_paused) print('Quitting viewer...')