MCPcopy Create free account
hub / github.com/apple/ml-pointersect / Test_Compute_XYZ_W_From_UV

Class Test_Compute_XYZ_W_From_UV

tests/plib/test_utils.py:212–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

210
211
212class Test_Compute_XYZ_W_From_UV(unittest.TestCase):
213
214 def test(self):
215 width_px, height_px = 300, 200
216 num_cam_poses = 5
217 z_map = torch.rand(num_cam_poses, height_px, width_px) * 10 + 0.1 # (m, h, w)
218
219 f = 40.
220 cam_poses = rigid_motion.generate_random_camera_poses(
221 n=num_cam_poses,
222 max_angle=180.,
223 min_r=0.5,
224 max_r=1.5,
225 )
226 cam_poses = utils.to_tensor(cam_poses, dtype=torch.float)
227 cam_poses = torch.stack(cam_poses, dim=0) # (m, 4, 4)
228
229 intrinsics = torch.tensor([
230 [f, 0., width_px * 0.5],
231 [0., f, height_px * 0.5],
232 [0, 0, 1],
233 ]).expand(num_cam_poses, 3, 3) # (m, 3, 3)
234
235 # gt
236 out_dict = utils.compute_3d_xyz(
237 z_map=z_map,
238 intrinsic=intrinsics,
239 H_c2w=cam_poses,
240 )
241 xyz_gt = out_dict['xyz_w'] # (m, h, w, 3)
242 # print(xyz_gt.shape)
243
244 # new
245 u, v = torch.meshgrid(
246 torch.arange(0, width_px),
247 torch.arange(0, height_px),
248 indexing='xy',
249 )
250 u = u + 0.5
251 v = v + 0.5
252 # print(f'u.shape = {u.shape}')
253 # print(f'v.shape = {v.shape}')
254 # print(f'z_map.shape = {v.shape}')
255
256 uv_c = torch.stack([u, v], dim=-1) # (h, w, 2)
257 # z_c = z_map[:, uv_c[..., 1], uv_c[..., 0]] # (n, h, w)
258 z_c = z_map
259
260
261 uv_c = uv_c.expand(num_cam_poses, -1, -1, -1) # (n, h, w, 2)
262 # print(f'uv_c.shape = {uv_c.shape}')
263 # print(f'z_c.shape = {z_c.shape}')
264
265 xyz_w = utils.compute_xyz_w_from_uv(
266 uv_c=uv_c,
267 z_c=z_c,
268 intrinsic=intrinsics,
269 H_c2w=cam_poses,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected