Exemplo n.º 1
0
    def test_check_corner_case(self, device, dtype):
        trans = torch.tensor(
            [[[0.0, 0.0, 1.0], [0.0, 2.0, 0.0], [0.5, 0.0, 0.0]]],
            device=device,
            dtype=dtype)

        trans_expected = trans.clone()

        trans_norm = epi.normalize_transformation(trans)
        assert_close(trans_norm, trans_expected, atol=1e-4, rtol=1e-4)
Exemplo n.º 2
0
    def test_check_last_val(self, device, dtype):
        trans = torch.tensor(
            [[[0.0, 0.0, 1.0], [0.0, 2.0, 0.0], [0.5, 0.0, 0.5]]],
            device=device,
            dtype=dtype)

        trans_expected = torch.tensor(
            [[[0.0, 0.0, 2.0], [0.0, 4.0, 0.0], [1.0, 0.0, 1.0]]],
            device=device,
            dtype=dtype)

        trans_norm = epi.normalize_transformation(trans)
        assert_allclose(trans_norm, trans_expected, atol=1e-4, rtol=1e-4)
Exemplo n.º 3
0
def generate_two_view_random_scene(device: torch.device = torch.device("cpu"),
                                   dtype: torch.dtype = torch.float32
                                   ) -> Dict[str, torch.Tensor]:

    num_views: int = 2
    num_points: int = 30

    scene: Dict[str, torch.Tensor] = epi.generate_scene(num_views, num_points)

    # internal parameters (same K)
    K1 = scene['K'].to(device, dtype)
    K2 = K1.clone()

    # rotation
    R1 = scene['R'][0:1].to(device, dtype)
    R2 = scene['R'][1:2].to(device, dtype)

    # translation
    t1 = scene['t'][0:1].to(device, dtype)
    t2 = scene['t'][1:2].to(device, dtype)

    # projection matrix, P = K(R|t)
    P1 = scene['P'][0:1].to(device, dtype)
    P2 = scene['P'][1:2].to(device, dtype)

    # fundamental matrix
    F_mat = epi.fundamental_from_projections(P1[..., :3, :], P2[..., :3, :])

    F_mat = epi.normalize_transformation(F_mat)

    # points 3d
    X = scene['points3d'].to(device, dtype)

    # projected points
    x1 = scene['points2d'][0:1].to(device, dtype)
    x2 = scene['points2d'][1:2].to(device, dtype)

    return dict(K1=K1,
                K2=K2,
                R1=R1,
                R2=R2,
                t1=t1,
                t2=t2,
                P1=P1,
                P2=P2,
                F=F_mat,
                X=X,
                x1=x1,
                x2=x2)
Exemplo n.º 4
0
    def test_from_to_projections(self, device, dtype):
        P1 = torch.tensor([[
            [1., 0., 0., 0.],
            [0., 1., 0., 0.],
            [1., 0., 1., 0.],
        ]],
                          device=device,
                          dtype=dtype)

        P2 = torch.tensor([[
            [1., 1., 1., 3.],
            [0., 2., 0., 3.],
            [0., 1., 1., 0.],
        ]],
                          device=device,
                          dtype=dtype)

        F_mat = epi.fundamental_from_projections(P1, P2)
        P_mat = epi.projections_from_fundamental(F_mat)
        F_hat = epi.fundamental_from_projections(P_mat[..., 0], P_mat[..., 1])

        F_mat_norm = epi.normalize_transformation(F_mat)
        F_hat_norm = epi.normalize_transformation(F_hat)
        assert_allclose(F_mat_norm, F_hat_norm)
Exemplo n.º 5
0
 def test_shape(self, batch_size, rows, cols, device, dtype):
     B, N, M = batch_size, rows, cols
     trans = torch.rand(B, N, M, device=device, dtype=dtype)
     trans_norm = epi.normalize_transformation(trans)
     assert trans_norm.shape == (B, N, M)
Exemplo n.º 6
0
 def test_smoke(self, device, dtype):
     trans = torch.rand(2, 2, device=device, dtype=dtype)
     trans_norm = epi.normalize_transformation(trans)
     assert trans_norm.shape == (2, 2)