MCPcopy
hub / github.com/junshutang/Make-It-3D / depth2point

Function depth2point

nerf/refine_utils.py:129–152  ·  view source on GitHub ↗
(D, alphamask, c2w, gt_rgb, H, W, cam)

Source from the content-addressed store, hash-verified

127 return v_list[arr], v_color_list[arr]
128
129def depth2point(D, alphamask, c2w, gt_rgb, H, W, cam):
130 K = cam
131 x, y = np.meshgrid(np.arange(D.shape[1]), np.arange(D.shape[0]))
132 cam_xyz = np.vstack(( \
133 x.reshape(-1), \
134 y.reshape(-1), \
135 np.ones(len(D.reshape(-1)))))
136 v = np.linalg.inv(cam).dot(cam_xyz).T
137 v = v * np.tile(D.reshape((-1,1)), (1,3))
138 v = v[alphamask.reshape(-1)==1]
139 v = np.matmul(v,c2w[:3,:3].T)+c2w[:3, 3:].T
140 # save_mesh = trimesh.points.PointCloud(vertices = v)
141 # save_mesh.export(outputdir + '/teddy_depth_fix.obj')
142
143 w2c = np.linalg.inv(c2w)
144 mask_cano = z_buffer(v, w2c, H, W, K)
145 v = v[mask_cano,:] #有color的点
146
147 xy,_ = project(v ,K, w2c[:3,:4])
148 gt_rgb = torch.Tensor(gt_rgb[None,...]).permute(0,3,1,2)
149 xy =torch.Tensor(xy[None,None,...])/H*2.-1.
150 v_color=F.grid_sample(gt_rgb,xy)
151 v_color = v_color.squeeze().permute(1,0).cpu().numpy()
152 return v, v_color
153
154def project(xyz, K, RT):
155 xyz = np.dot(xyz, RT[:, :3].T) + RT[:, 3:].T

Callers 1

load_viewsFunction · 0.85

Calls 3

z_bufferFunction · 0.85
projectFunction · 0.85
cpuMethod · 0.45

Tested by

no test coverage detected