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

Class Test_compute_3d_xyz

tests/plib/test_render.py:9–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7
8
9class Test_compute_3d_xyz(unittest.TestCase):
10
11 def _get_random_setup(self):
12 intrinsics = np.array([
13 [128., 0, 128.],
14 [0., 128., 128.],
15 [0., 0., 1.],
16 ])
17 w = 256
18 h = 256
19 z_map = np.random.rand(h, w) * 10. + 1.
20 img = np.random.rand(h, w, 3)
21 r_angles = np.random.rand(3) * 60. # in degree
22 R = Rotation.from_euler('xyz', r_angles, degrees=True).as_matrix() # (3,3) rotation matrix
23 t = np.random.rand(3)
24 H_c2w = np.eye(4)
25 H_c2w[:3, :3] = R
26 H_c2w[:3, 3] = t
27
28 return dict(
29 intrinsics=intrinsics,
30 z_map=z_map,
31 img=img,
32 H_c2w=H_c2w,
33 )
34
35 def _test(self, subsample: int):
36 info_dict = self._get_random_setup()
37 points1, _ = generate_point(
38 rgb_image=info_dict['img'],
39 depth_image=info_dict['z_map'],
40 intrinsic=info_dict['intrinsics'],
41 subsample=subsample,
42 world_coordinate=True,
43 pose=info_dict['H_c2w'],
44 ) # (N, 3)
45
46 info_dict_t = utils.to_tensor(info_dict)
47 points2 = utils.compute_3d_xyz(
48 z_map=info_dict_t['z_map'],
49 intrinsic=info_dict_t['intrinsics'],
50 H_c2w=info_dict_t['H_c2w'],
51 subsample=subsample,
52 ) # (h, w, 3)
53 points2 = points2.reshape(-1, 3)
54
55 assert torch.allclose(torch.from_numpy(points1), points2)
56
57 def test_1(self):
58 self._test(subsample=1)
59
60 def test_2(self):
61 self._test(subsample=2)
62
63
64

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected