Exemplo n.º 1
0
    def test_from_to_essential(self, device, dtype):
        scene = utils.generate_two_view_random_scene(device, dtype)

        F_mat = scene['F']
        E_mat = epi.essential_from_fundamental(F_mat, scene['K1'], scene['K2'])
        F_hat = epi.fundamental_from_essential(E_mat, scene['K1'], scene['K2'])

        F_mat_norm = epi.normalize_transformation(F_mat)
        F_hat_norm = epi.normalize_transformation(F_hat)
        assert_close(F_mat_norm, F_hat_norm, atol=1e-4, rtol=1e-4)
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def test_synthetic_sampson(self, device, dtype):

        scene: Dict[str, torch.Tensor] = utils.generate_two_view_random_scene(device, dtype)

        x1 = scene['x1']
        x2 = scene['x2']

        weights = torch.ones_like(x1)[..., 0]
        F_est = epi.find_fundamental(x1, x2, weights)

        error = epi.sampson_epipolar_distance(x1, x2, F_est)
        assert_close(error, torch.tensor(0.0, device=device, dtype=dtype), atol=1e-4, rtol=1e-4)
Exemplo n.º 4
0
    def test_from_fundamental(self, device, dtype):

        scene = utils.generate_two_view_random_scene(device, dtype)

        F_mat = scene['F']

        K1 = scene['K1']
        K2 = scene['K2']

        E_mat = epi.essential_from_fundamental(F_mat, K1, K2)
        F_hat = epi.fundamental_from_essential(E_mat, K1, K2)

        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_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)
Exemplo n.º 6
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()