Пример #1
0
    def test_simple(self, device):
        # this is for default normalize_points=False
        depth = 2 * torch.tensor([[[
            [1., 1., 1.],
            [1., 1., 1.],
            [1., 1., 1.],
            [1., 1., 1.],
        ]]]).to(device)

        camera_matrix = torch.tensor([[
            [1., 0., 0.],
            [0., 1., 0.],
            [0., 0., 1.],
        ]]).to(device)

        normals_expected = torch.tensor([[[
            [0., 0., 0.],
            [0., 0., 0.],
            [0., 0., 0.],
            [0., 0., 0.],
        ], [
            [0., 0., 0.],
            [0., 0., 0.],
            [0., 0., 0.],
            [0., 0., 0.],
        ], [
            [1., 1., 1.],
            [1., 1., 1.],
            [1., 1., 1.],
            [1., 1., 1.],
        ]]]).to(device)

        normals = kornia.depth_to_normals(
            depth, camera_matrix)  # default is normalize_points=False
        assert_allclose(normals, normals_expected, 1e-3, 1e-3)
Пример #2
0
    def test_simple(self, device):
        depth = 2 * torch.tensor([[[
            [1., 1., 1.],
            [1., 1., 1.],
            [1., 1., 1.],
            [1., 1., 1.],
        ]]]).to(device)

        camera_matrix = torch.tensor([[
            [1., 0., 0.],
            [0., 1., 0.],
            [0., 0., 1.],
        ]]).to(device)

        normals_expected = torch.tensor([[[
            [0.3432, 0.4861, 0.7628],
            [0.2873, 0.4260, 0.6672],
            [0.2284, 0.3683, 0.5596],
            [0.1695, 0.2980, 0.4496],
        ],
                                          [
                                              [0.3432, 0.2873, 0.2363],
                                              [0.4861, 0.4260, 0.3785],
                                              [0.8079, 0.7261, 0.6529],
                                              [0.8948, 0.8237, 0.7543],
                                          ],
                                          [
                                              [0.8743, 0.8253, 0.6019],
                                              [0.8253, 0.7981, 0.6415],
                                              [0.5432, 0.5807, 0.5105],
                                              [0.4129, 0.4824, 0.4784],
                                          ]]]).to(device)

        normals = kornia.depth_to_normals(depth, camera_matrix)
        assert_allclose(normals, normals_expected, 1e-3, 1e-3)
Пример #3
0
    def test_shapes(self, batch_size, device, dtype):
        depth = torch.rand(batch_size, 1, 3, 4, device=device, dtype=dtype)
        camera_matrix = torch.rand(batch_size,
                                   3,
                                   3,
                                   device=device,
                                   dtype=dtype)

        points3d = kornia.depth_to_normals(depth, camera_matrix)
        assert points3d.shape == (batch_size, 3, 3, 4)
Пример #4
0
    def test_simple_normalized(self, device, dtype):
        # this is for default normalize_points=False
        depth = 2 * torch.tensor([[[
            [1., 1., 1.],
            [1., 1., 1.],
            [1., 1., 1.],
            [1., 1., 1.],
        ]]],
                                 device=device,
                                 dtype=dtype)

        camera_matrix = torch.tensor([[
            [1., 0., 0.],
            [0., 1., 0.],
            [0., 0., 1.],
        ]],
                                     device=device,
                                     dtype=dtype)

        normals_expected = torch.tensor([[[
            [0.3432, 0.4861, 0.7628],
            [0.2873, 0.4260, 0.6672],
            [0.2284, 0.3683, 0.5596],
            [0.1695, 0.2980, 0.4496],
        ],
                                          [
                                              [0.3432, 0.2873, 0.2363],
                                              [0.4861, 0.4260, 0.3785],
                                              [0.8079, 0.7261, 0.6529],
                                              [0.8948, 0.8237, 0.7543],
                                          ],
                                          [
                                              [0.8743, 0.8253, 0.6019],
                                              [0.8253, 0.7981, 0.6415],
                                              [0.5432, 0.5807, 0.5105],
                                              [0.4129, 0.4824, 0.4784],
                                          ]]],
                                        device=device,
                                        dtype=dtype)

        normals = kornia.depth_to_normals(depth,
                                          camera_matrix,
                                          normalize_points=True)
        assert_allclose(normals, normals_expected, 1e-3, 1e-3)
Пример #5
0
    def test_simple(self, device, dtype):
        # this is for default normalize_points=False
        depth = 2 * torch.tensor(
            [[[[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]]], device=device, dtype=dtype
        )

        camera_matrix = torch.tensor([[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]], device=device, dtype=dtype)

        normals_expected = torch.tensor(
            [
                [
                    [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
                    [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
                    [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]],
                ]
            ],
            device=device,
            dtype=dtype,
        )

        normals = kornia.depth_to_normals(depth, camera_matrix)  # default is normalize_points=False
        assert_close(normals, normals_expected, rtol=1e-3, atol=1e-3)
Пример #6
0
    def test_shapes_broadcast(self, device, batch_size):
        depth = torch.rand(batch_size, 1, 3, 4).to(device)
        camera_matrix = torch.rand(1, 3, 3).to(device)

        points3d = kornia.depth_to_normals(depth, camera_matrix)
        assert points3d.shape == (batch_size, 3, 3, 4)
Пример #7
0
    def test_smoke(self, device):
        depth = torch.rand(1, 1, 3, 4).to(device)
        camera_matrix = torch.rand(1, 3, 3).to(device)

        points3d = kornia.depth_to_normals(depth, camera_matrix)
        assert points3d.shape == (1, 3, 3, 4)