Example #1
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)
Example #2
0
 def test_shift(self, device, dtype):
     pts1 = torch.zeros(3, 2, device=device, dtype=dtype)[None]
     pts2 = torch.tensor([[2, 0.0], [2, 1], [2, 2.0]],
                         device=device,
                         dtype=dtype)[None]
     Fm = torch.tensor([[0.0, 0.0, 0.0], [0.0, 0.0, -1.0], [0.0, 1.0, 0.0]],
                       dtype=dtype,
                       device=device)[None]
     expected = torch.tensor([0.0, 0.5, 2.0], device=device,
                             dtype=dtype)[None]
     assert_close(epi.sampson_epipolar_distance(pts1, pts2, Fm),
                  expected,
                  atol=1e-4,
                  rtol=1e-4)
Example #3
0
 def test_real_clean(self, device, dtype, data):
     torch.random.manual_seed(0)
     # generate input data
     data_dev = utils.dict_to(data, device, dtype)
     pts_src = data_dev['pts0']
     pts_dst = data_dev['pts1']
     # compute transform from source to target
     ransac = RANSAC('fundamental',
                     inl_th=0.5,
                     max_iter=20,
                     max_lo_iters=10).to(device=device, dtype=dtype)
     fundamental_matrix, _ = ransac(pts_src, pts_dst)
     gross_errors = (sampson_epipolar_distance(pts_src[None],
                                               pts_dst[None],
                                               fundamental_matrix[None],
                                               squared=False) > 1.0)
     assert gross_errors.sum().item() == 0
Example #4
0
    def test_real_dirty(self, device, dtype, data):
        torch.random.manual_seed(0)
        # generate input data
        data_dev = utils.dict_to(data, device, dtype)
        pts_src = data_dev['pts0']
        pts_dst = data_dev['pts1']

        kp1 = data_dev['loftr_indoor_tentatives0']
        kp2 = data_dev['loftr_indoor_tentatives1']

        ransac = RANSAC('fundamental',
                        inl_th=1.0,
                        max_iter=20,
                        max_lo_iters=10).to(device=device, dtype=dtype)
        # compute transform from source to target
        fundamental_matrix, _ = ransac(kp1, kp2)
        gross_errors = (sampson_epipolar_distance(pts_src[None],
                                                  pts_dst[None],
                                                  fundamental_matrix[None],
                                                  squared=False) > 10.0)
        assert gross_errors.sum().item() < 2
Example #5
0
 def test_batch(self, device, dtype):
     batch_size = 5
     pts1 = torch.rand(batch_size, 4, 3, device=device, dtype=dtype)
     pts2 = torch.rand(batch_size, 4, 3, device=device, dtype=dtype)
     Fm = utils.create_random_fundamental_matrix(1).type_as(pts1)
     assert epi.sampson_epipolar_distance(pts1, pts2, Fm).shape == (5, 4)