import cv2 import pangolin import numpy as np import OpenGL.GL as gl
fx = 721.5377 fy = 721.5377 cx = 607.1928 cy = 185.2157 B = 0.54
img_disp = cv2.imread('000004_10_disp.png', -1) / 256. imgL = cv2.imread('000004_10.jpg') imgL = cv2.cvtColor(imgL, cv2.COLOR_BGR2RGB)
h, w = imgL.shape[:2] f = 0.5 * w points, colors = [], []
for v in range(h): for u in range(w): disp = img_disp[v, u] if disp > 0.: depth = B * fx / disp z_w = depth x_w = (u - cx) * z_w / fx y_w = (v - cy) * z_w / fy points.append([x_w, y_w, z_w]) colors.append(imgL[v, u]) points = np.array(points) colors = np.array(colors) / 255.
pangolin.CreateWindowAndBind('Main', 640, 480) gl.glEnable(gl.GL_DEPTH_TEST)
scam = pangolin.OpenGlRenderState( pangolin.ProjectionMatrix(640, 480, 2000, 2000, 320, 240, 0.1, 1000), pangolin.ModelViewLookAt(0, 0, -20, 0, 0, 0, 0, -1, 0)) 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(3) pangolin.DrawPoints(points, colors) pangolin.FinishFrame()
|