예제 #1
0
 def test_smoke_multi_batch(self, device, dtype):
     points_2d = torch.zeros(2, 3, 2, device=device, dtype=dtype)
     depth = torch.ones(2, 3, 1, device=device, dtype=dtype)
     camera_matrix = torch.eye(3, device=device,
                               dtype=dtype).expand(2, 3, -1, -1)
     point_3d = kornia.unproject_points(points_2d, depth, camera_matrix)
     assert point_3d.shape == (2, 3, 3)
예제 #2
0
 def test_unproject_center(self):
     point_2d = torch.tensor([[0., 0.]])
     depth = torch.tensor([[2.]])
     camera_matrix = torch.tensor([
         [1., 0., 0.],
         [0., 1., 0.],
         [0., 0., 1.],
     ])
     expected = torch.tensor([[0., 0., 2.]])
     actual = kornia.unproject_points(point_2d, depth, camera_matrix)
     assert_allclose(actual, expected)
예제 #3
0
 def test_project_and_unproject(self):
     point_3d = torch.tensor([[10., 2., 30.]])
     depth = point_3d[..., -1:]
     camera_matrix = torch.tensor([[
         [2746., 0., 991.],
         [0., 2748., 619.],
         [0., 0., 1.],
     ]])
     point_2d = kornia.project_points(point_3d, camera_matrix)
     point_3d_hat = kornia.unproject_points(point_2d, depth, camera_matrix)
     assert_allclose(point_3d, point_3d_hat)
예제 #4
0
 def test_unproject_and_project(self):
     point_2d = torch.tensor([[0., 0.]])
     depth = torch.tensor([[2.]])
     camera_matrix = torch.tensor([
         [1., 0., 0.],
         [0., 1., 0.],
         [0., 0., 1.],
     ])
     point_3d = kornia.unproject_points(point_2d, depth, camera_matrix)
     point_2d_hat = kornia.project_points(point_3d, camera_matrix)
     assert_allclose(point_2d, point_2d_hat)
예제 #5
0
 def test_unproject_center_normalize(self, device):
     point_2d = torch.tensor([[0., 0.]]).to(device)
     depth = torch.tensor([[2.]]).to(device)
     camera_matrix = torch.tensor([
         [1., 0., 0.],
         [0., 1., 0.],
         [0., 0., 1.],
     ]).to(device)
     expected = torch.tensor([[0., 0., 2.]]).to(device)
     actual = kornia.unproject_points(point_2d, depth, camera_matrix, True)
     assert_allclose(actual, expected)
예제 #6
0
    def test_jit(self):
        @torch.jit.script
        def op_script(points_2d, depth, camera_matrix):
            return kornia.unproject_points(points_2d, depth, camera_matrix,
                                           False)

        points_2d = torch.zeros(1, 2)
        depth = torch.ones(1, 1)
        camera_matrix = torch.eye(3).expand(1, -1, -1)
        actual = op_script(points_2d, depth, camera_matrix)
        expected = kornia.unproject_points(points_2d, depth, camera_matrix)

        assert_allclose(actual, expected)
예제 #7
0
 def test_unproject_center(self, device, dtype):
     point_2d = torch.tensor([[0., 0.]], device=device, dtype=dtype)
     depth = torch.tensor([[2.]], device=device, dtype=dtype)
     camera_matrix = torch.tensor([
         [1., 0., 0.],
         [0., 1., 0.],
         [0., 0., 1.],
     ],
                                  device=device,
                                  dtype=dtype)
     expected = torch.tensor([[0., 0., 2.]], device=device, dtype=dtype)
     actual = kornia.unproject_points(point_2d, depth, camera_matrix)
     assert_allclose(actual, expected, atol=1e-4, rtol=1e-4)
예제 #8
0
 def test_unproject_and_project(self, device, dtype):
     point_2d = torch.tensor([[0., 0.]], device=device, dtype=dtype)
     depth = torch.tensor([[2.]], device=device, dtype=dtype)
     camera_matrix = torch.tensor([
         [1., 0., 0.],
         [0., 1., 0.],
         [0., 0., 1.],
     ],
                                  device=device,
                                  dtype=dtype)
     point_3d = kornia.unproject_points(point_2d, depth, camera_matrix)
     point_2d_hat = kornia.project_points(point_3d, camera_matrix)
     assert_allclose(point_2d, point_2d_hat, atol=1e-4, rtol=1e-4)
예제 #9
0
    def test_jit(self, device, dtype):
        @torch.jit.script
        def op_script(points_2d, depth, camera_matrix):
            return kornia.unproject_points(points_2d, depth, camera_matrix,
                                           False)

        points_2d = torch.zeros(1, 2, device=device, dtype=dtype)
        depth = torch.ones(1, 1, device=device, dtype=dtype)
        camera_matrix = torch.eye(3, device=device,
                                  dtype=dtype).expand(1, -1, -1)
        actual = op_script(points_2d, depth, camera_matrix)
        expected = kornia.unproject_points(points_2d, depth, camera_matrix)

        assert_allclose(actual, expected, atol=1e-4, rtol=1e-4)
예제 #10
0
    def samplePosition(self, num_samples=1):
        """
        Returns
        -------
        t : torch.Tensor of shape (num_samples, 3)
        """

        camera_dist = self.renderer.t[0, 0, 2]

        px_bounds = torch.tensor([[0, 0], [self.image_size, self.image_size]],
                                 dtype=torch.float).cuda()
        depth_coords = torch.full(px_bounds.shape[0:1],
                                  camera_dist)[..., None].cuda()
        xy_bounds = kornia.unproject_points(px_bounds, depth_coords,
                                            self.renderer.K)[:, :-1]

        xy_samples = _sample_uniform(num_samples, xy_bounds[0], xy_bounds[1])
        z_samples = torch.full((num_samples, 1), 0).cuda()

        t = torch.cat((xy_samples, z_samples), dim=1)

        return t.cuda()
예제 #11
0
 def test_smoke_batch(self):
     points_2d = torch.zeros(2, 2)
     depth = torch.ones(2, 1)
     camera_matrix = torch.eye(3).expand(2, -1, -1)
     point_3d = kornia.unproject_points(points_2d, depth, camera_matrix)
     assert point_3d.shape == (2, 3)
예제 #12
0
 def op_script(points_2d, depth, camera_matrix):
     return kornia.unproject_points(points_2d, depth, camera_matrix,
                                    False)
예제 #13
0
 def test_smoke(self, device):
     points_2d = torch.zeros(1, 2).to(device)
     depth = torch.ones(1, 1).to(device)
     camera_matrix = torch.eye(3).expand(1, -1, -1).to(device)
     point_3d = kornia.unproject_points(points_2d, depth, camera_matrix)
     assert point_3d.shape == (1, 3)