예제 #1
0
def test_outliers_relative_pose_ransac(pairs_and_their_E):
    for f1, f2, _, pose in pairs_and_their_E:
        points = np.concatenate((f1, f2), axis=1)

        scale = 1e-3
        points += np.random.rand(*points.shape) * scale

        ratio_outliers = 0.3
        add_outliers(ratio_outliers, points, 0.1, 1.0)

        f1, f2 = points[:, 0:3], points[:, 3:6]
        f1 /= np.linalg.norm(f1, axis=1)[:, None]
        f2 /= np.linalg.norm(f2, axis=1)[:, None]

        scale_eps_ratio = 1e-1
        params = pyrobust.RobustEstimatorParams()
        params.iterations = 1000
        result = pyrobust.ransac_relative_pose(f1, f2,
                                               scale * (1.0 + scale_eps_ratio),
                                               params,
                                               pyrobust.RansacType.RANSAC)

        pose.translation /= np.linalg.norm(pose.translation)
        expected = pose.get_Rt()

        tolerance = 0.1
        inliers_count = (1 - ratio_outliers) * len(points)
        assert np.isclose(len(result.inliers_indices),
                          inliers_count,
                          rtol=tolerance)

    assert np.linalg.norm(expected - result.lo_model, ord='fro') < 16e-2
예제 #2
0
def relative_pose_ransac(b1, b2, method, threshold, iterations, probability):
    # in-house estimation
    if in_house_multiview:
        threshold = np.arccos(1 - threshold)
        params = pyrobust.RobustEstimatorParams()
        params.iterations = 1000
        result = pyrobust.ransac_relative_pose(b1, b2, threshold, params,
                                               pyrobust.RansacType.RANSAC)

        Rt = result.lo_model.copy()
        R, t = Rt[:3, :3].copy(), Rt[:, 3].copy()
        Rt[:3, :3] = R.T
        Rt[:, 3] = -R.T.dot(t)
        return Rt

    # fallback to opengv
    else:
        try:
            return pyopengv.relative_pose_ransac(b1,
                                                 b2,
                                                 method,
                                                 threshold,
                                                 iterations=iterations,
                                                 probability=probability)
        except Exception:
            # Older versions of pyopengv do not accept the probability argument.
            return pyopengv.relative_pose_ransac(b1, b2, method, threshold,
                                                 iterations)
예제 #3
0
def test_outliers_relative_pose_ransac(one_pair_and_its_E):
    f1, f2, _, pose = one_pair_and_its_E
    points = np.concatenate((f1, f2), axis=1)

    scale = 1e-3
    points += np.random.rand(*points.shape) * scale

    ratio_outliers = 0.3
    add_outliers(ratio_outliers, points, 0.1, 1.0)

    f1, f2 = points[:, 0:3], points[:, 3:6]
    f1 /= np.linalg.norm(f1, axis=1)[:, None]
    f2 /= np.linalg.norm(f2, axis=1)[:, None]

    params = pyrobust.RobustEstimatorParams()
    params.iterations = 1000
    result = pyrobust.ransac_relative_pose(f1, f2, scale, params,
                                           pyrobust.RansacType.RANSAC)

    pose.translation /= np.linalg.norm(pose.translation)
    expected = pose.get_Rt()

    tolerance = 0.04  # some outliers might have been moved along the epipolar
    inliers_count = (1 - ratio_outliers) * len(points)
    assert np.isclose(len(result.inliers_indices),
                      inliers_count,
                      rtol=tolerance)

    assert np.linalg.norm(expected - result.lo_model, ord='fro') < 8e-2
예제 #4
0
def relative_pose_ransac(b1, b2, threshold, iterations, probability):
    params = pyrobust.RobustEstimatorParams()
    params.iterations = 1000
    result = pyrobust.ransac_relative_pose(b1, b2, threshold, params, pyrobust.RansacType.RANSAC)

    Rt = result.lo_model.copy()
    R, t = Rt[:3, :3].copy(), Rt[:, 3].copy()
    Rt[:3, :3] = R.T
    Rt[:, 3] = -R.T.dot(t)
    return Rt
예제 #5
0
def relative_pose_ransac(
    b1: np.ndarray,
    b2: np.ndarray,
    threshold: float,
    iterations: int,
    probability: float,
) -> np.ndarray:
    params = pyrobust.RobustEstimatorParams()
    params.iterations = iterations
    result = pyrobust.ransac_relative_pose(b1, b2, threshold, params,
                                           pyrobust.RansacType.RANSAC)

    Rt = result.lo_model.copy()
    R, t = Rt[:3, :3].copy(), Rt[:, 3].copy()
    Rt[:3, :3] = R.T
    Rt[:, 3] = -R.T.dot(t)
    return Rt