示例#1
0
def relative_pose_ransac_rotation_only(b1, b2, threshold, iterations,
                                       probability):
    params = pyrobust.RobustEstimatorParams()
    params.iterations = 1000
    result = pyrobust.ransac_relative_rotation(b1, b2, threshold, params,
                                               pyrobust.RansacType.RANSAC)
    return result.lo_model.T
示例#2
0
def relative_pose_ransac_rotation_only(
    b1: np.ndarray,
    b2: np.ndarray,
    threshold: float,
    iterations: int,
    probability: float,
) -> np.ndarray:
    params = pyrobust.RobustEstimatorParams()
    params.iterations = iterations
    result = pyrobust.ransac_relative_rotation(b1, b2, threshold, params,
                                               pyrobust.RansacType.RANSAC)
    return result.lo_model.T
示例#3
0
def test_outliers_relative_rotation_ransac(pairs_and_their_E):
    for f1, _, _, _ in pairs_and_their_E:

        vec_x = np.random.rand(3)
        vec_x /= np.linalg.norm(vec_x)
        vec_y = np.array([-vec_x[1], vec_x[0], 0.])
        vec_y /= np.linalg.norm(vec_y)
        vec_z = np.cross(vec_x, vec_y)

        rotation = np.array([vec_x, vec_y, vec_z])

        f1 /= np.linalg.norm(f1, axis=1)[:, None]
        f2 = [rotation.dot(x) for x in f1]

        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_rotation(f1, f2,
                                                   np.sqrt(3 * scale * scale),
                                                   params,
                                                   pyrobust.RansacType.RANSAC)

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

        assert np.linalg.norm(rotation - result.lo_model, ord='fro') < 8e-2
示例#4
0
def relative_pose_ransac_rotation_only(b1, b2, 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_rotation(b1, b2, threshold, params,
                                                   pyrobust.RansacType.RANSAC)
        return result.lo_model.T
    else:
        try:
            return pyopengv.relative_pose_ransac_rotation_only(
                b1,
                b2,
                threshold,
                iterations=iterations,
                probability=probability)
        except Exception:
            # Older versions of pyopengv do not accept the probability argument.
            return pyopengv.relative_pose_ransac_rotation_only(
                b1, b2, threshold, iterations)