예제 #1
0
    def test_unbatched(self, num_points, device, dtype):
        N = num_points
        E_mat = torch.rand(3, 3, device=device, dtype=dtype)
        K1 = torch.rand(3, 3, device=device, dtype=dtype)
        K2 = torch.rand(3, 3, device=device, dtype=dtype)
        x1 = torch.rand(N, 2, device=device, dtype=dtype)
        x2 = torch.rand(N, 2, device=device, dtype=dtype)

        R, t, X = epi.motion_from_essential_choose_solution(
            E_mat, K1, K2, x1[1:-1, :], x2[1:-1, :])
        assert R.shape == (3, 3)
        assert t.shape == (3, 1)
        assert X.shape == (N - 2, 3)

        mask = torch.zeros(N, dtype=torch.bool, device=device)
        mask[1:-1] = True
        Rm, tm, Xm = epi.motion_from_essential_choose_solution(E_mat,
                                                               K1,
                                                               K2,
                                                               x1,
                                                               x2,
                                                               mask=mask)

        assert_allclose(R, Rm)
        assert_allclose(t, tm)
        assert_allclose(X, Xm[1:-1, :])
예제 #2
0
    def test_masking(self, device, dtype):
        E_mat = torch.rand(2, 3, 3, device=device, dtype=dtype)
        K1 = torch.rand(2, 3, 3, device=device, dtype=dtype)
        K2 = torch.rand(2, 3, 3, device=device, dtype=dtype)
        x1 = torch.rand(2, 10, 2, device=device, dtype=dtype)
        x2 = torch.rand(2, 10, 2, device=device, dtype=dtype)

        R, t, X = epi.motion_from_essential_choose_solution(E_mat, K1, K2, x1[:, 1:-1, :], x2[:, 1:-1, :])

        mask = torch.zeros(2, 10, dtype=torch.bool, device=device)
        mask[:, 1:-1] = True
        Rm, tm, Xm = epi.motion_from_essential_choose_solution(E_mat, K1, K2, x1, x2, mask=mask)

        assert_close(R, Rm)
        assert_close(t, tm)
        assert_close(X, Xm[:, 1:-1, :])
예제 #3
0
 def test_smoke(self, device, dtype):
     E_mat = torch.rand(1, 3, 3, device=device, dtype=dtype)
     K1 = torch.rand(1, 3, 3, device=device, dtype=dtype)
     K2 = torch.rand(1, 3, 3, device=device, dtype=dtype)
     x1 = torch.rand(1, 1, 2, device=device, dtype=dtype)
     x2 = torch.rand(1, 1, 2, device=device, dtype=dtype)
     R, t, X = epi.motion_from_essential_choose_solution(E_mat, K1, K2, x1, x2)
     assert R.shape == (1, 3, 3)
     assert t.shape == (1, 3, 1)
     assert X.shape == (1, 1, 3)
예제 #4
0
 def test_shape(self, batch_size, num_points, device, dtype):
     B, N = batch_size, num_points
     E_mat = torch.rand(B, 3, 3, device=device, dtype=dtype)
     K1 = torch.rand(B, 3, 3, device=device, dtype=dtype)
     K2 = torch.rand(1, 3, 3, device=device, dtype=dtype)  # check for broadcasting
     x1 = torch.rand(B, N, 2, device=device, dtype=dtype)
     x2 = torch.rand(B, 1, 2, device=device, dtype=dtype)  # check for broadcasting
     R, t, X = epi.motion_from_essential_choose_solution(E_mat, K1, K2, x1, x2)
     assert R.shape == (B, 3, 3)
     assert t.shape == (B, 3, 1)
     assert X.shape == (B, N, 3)
예제 #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)