def test_unproject_project_random(self): """Tests that unprojecting and projecting gives and identity mapping.""" tensor_size = np.random.randint(3) tensor_shape = np.random.randint(1, 10, size=(tensor_size)).tolist() random_point_2d = np.random.normal(size=tensor_shape + [2]) random_focal = np.random.normal(size=tensor_shape + [2]) random_principal_point = np.random.normal(size=tensor_shape + [2]) random_depth = np.random.normal(size=tensor_shape + [1]) point_3d = perspective.unproject(random_point_2d, random_depth, random_focal, random_principal_point) point_2d = perspective.project(point_3d, random_focal, random_principal_point) self.assertAllClose(random_point_2d, point_2d, rtol=1e-3)
def test_unproject_ray_random(self): """Tests that that ray is pointing toward the correct location.""" tensor_size = np.random.randint(3) tensor_shape = np.random.randint(1, 10, size=(tensor_size)).tolist() random_point_2d = np.random.normal(size=tensor_shape + [2]) random_focal = np.random.normal(size=tensor_shape + [2]) random_principal_point = np.random.normal(size=tensor_shape + [2]) random_depth = np.random.normal(size=tensor_shape + [1]) point_3d = perspective.unproject(random_point_2d, random_depth, random_focal, random_principal_point) ray_3d = perspective.ray(random_point_2d, random_focal, random_principal_point) ray_3d = random_depth * ray_3d self.assertAllClose(point_3d, ray_3d, rtol=1e-3)