Пример #1
0
 def test_shape(self, batch_size, num_points, device, dtype):
     B, N = batch_size, num_points
     points1 = torch.rand(B, N, 2, device=device, dtype=dtype)
     points2 = torch.rand(B, N, 2, device=device, dtype=dtype)
     weights = torch.ones(B, N, device=device, dtype=dtype)
     F_mat = epi.find_fundamental(points1, points2, weights)
     assert F_mat.shape == (B, 3, 3)
Пример #2
0
    def test_opencv(self, device, dtype):
        points1 = torch.tensor(
            [[[0.8569, 0.5982], [0.0059, 0.9649], [0.1968, 0.8846],
              [0.6084, 0.3467], [0.9633, 0.5274], [0.8941, 0.8939],
              [0.0863, 0.5133], [0.2645, 0.8882], [0.2411, 0.3045],
              [0.8199, 0.4107]]],
            device=device,
            dtype=dtype)

        points2 = torch.tensor(
            [[[0.0928, 0.3013], [0.0989, 0.9649], [0.0341, 0.4827],
              [0.8294, 0.4469], [0.2230, 0.2998], [0.1722, 0.8182],
              [0.5264, 0.8869], [0.8908, 0.1233], [0.2338, 0.7663],
              [0.4466, 0.5696]]],
            device=device,
            dtype=dtype)

        weights = torch.ones(1, 10, device=device, dtype=dtype)

        # generated with OpenCV using above points
        # import cv2
        # Fm_expected, _ = cv2.findFundamentalMat(
        #   points1.detach().numpy().reshape(-1, 1, 2),
        #   points2.detach().numpy().reshape(-1, 1, 2), cv2.FM_8POINT)

        Fm_expected = torch.tensor([[[-0.47408533, 0.22033807, -0.00346677],
                                     [0.54935973, 1.31080955, -1.25028275],
                                     [-0.36690215, -1.08143769, 1.]]],
                                   device=device,
                                   dtype=dtype)

        F_mat = epi.find_fundamental(points1, points2, weights)
        assert_allclose(F_mat, Fm_expected, rtol=1e-4, atol=1e-4)
Пример #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)
Пример #4
0
 def test_smoke(self, device, dtype):
     points1 = torch.rand(1, 1, 2, device=device, dtype=dtype)
     points2 = torch.rand(1, 1, 2, device=device, dtype=dtype)
     weights = torch.ones(1, 1, device=device, dtype=dtype)
     F_mat = epi.find_fundamental(points1, points2, weights)
     assert F_mat.shape == (1, 3, 3)