Exemple #1
0
 def test_smoke(self, device, dtype):
     R1 = torch.rand(1, 3, 3, device=device, dtype=dtype)
     t1 = torch.rand(1, 3, 1, device=device, dtype=dtype)
     R2 = torch.rand(1, 3, 3, device=device, dtype=dtype)
     t2 = torch.rand(1, 3, 1, device=device, dtype=dtype)
     E_mat = epi.essential_from_Rt(R1, t1, R2, t2)
     assert E_mat.shape == (1, 3, 3)
Exemple #2
0
 def test_shape(self, batch_size, device, dtype):
     B: int = batch_size
     R1 = torch.rand(B, 3, 3, device=device, dtype=dtype)
     t1 = torch.rand(B, 3, 1, device=device, dtype=dtype)
     R2 = torch.rand(1, 3, 3, device=device, dtype=dtype)  # check broadcasting
     t2 = torch.rand(B, 3, 1, device=device, dtype=dtype)
     E_mat = epi.essential_from_Rt(R1, t1, R2, t2)
     assert E_mat.shape == (B, 3, 3)
Exemple #3
0
    def test_from_fundamental_Rt(self, device, dtype):

        scene = utils.generate_two_view_random_scene(device, dtype)

        E_from_Rt = epi.essential_from_Rt(scene['R1'], scene['t1'], scene['R2'], scene['t2'])

        E_from_F = epi.essential_from_fundamental(scene['F'], scene['K1'], scene['K2'])

        E_from_Rt_norm = epi.normalize_transformation(E_from_Rt)
        E_from_F_norm = epi.normalize_transformation(E_from_F)
        # TODO: occasionally failed with error > 0.04
        assert_close(E_from_Rt_norm, E_from_F_norm, rtol=1e-3, atol=1e-3)
Exemple #4
0
    def test_two_view(self, device, dtype):

        scene = utils.generate_two_view_random_scene(device, dtype)

        E_mat = epi.essential_from_Rt(scene['R1'], scene['t1'], scene['R2'], scene['t2'])

        R, t = epi.relative_camera_motion(scene['R1'], scene['t1'], scene['R2'], scene['t2'])
        t = torch.nn.functional.normalize(t, dim=1)

        R_hat, t_hat, _ = epi.motion_from_essential_choose_solution(
            E_mat, scene['K1'], scene['K2'], scene['x1'], scene['x2']
        )

        assert_close(t, t_hat)
        assert_close(R, R_hat, rtol=1e-4, atol=1e-4)
Exemple #5
0
    def test_two_view(self, device, dtype):
        scene = utils.generate_two_view_random_scene(device, dtype)

        R1, t1 = scene['R1'], scene['t1']
        R2, t2 = scene['R2'], scene['t2']

        E_mat = epi.essential_from_Rt(R1, t1, R2, t2)

        R, t = epi.relative_camera_motion(R1, t1, R2, t2)
        t = torch.nn.functional.normalize(t, dim=1)

        Rs, ts = epi.motion_from_essential(E_mat)

        rot_error = (Rs - R).abs().sum((-2, -1))
        vec_error = (ts - t).abs().sum((-1))

        rtol: float = 1e-4
        assert (rot_error < rtol).any() & (vec_error < rtol).any()