def test_outliers_essential_ransac(pairs_and_their_E): for f1, f2, E, _ 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, 0.4) 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() result = pyrobust.ransac_essential(f1, f2, scale * (1.0 + scale_eps_ratio), params, pyrobust.RansacType.RANSAC) tolerance = 0.12 # 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)
def test_outliers_essential_ransac(one_pair_and_its_E): f1, f2, E, _ = 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.4 add_outliers(ratio_outliers, points, 0.1, 0.4) 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() result = pyrobust.ransac_essential(f1, f2, scale, params, pyrobust.RansacType.RANSAC) 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) # sometimes, the negative of E is the good one correct_found = 0 for sign in [-1, 1]: correct_found += np.linalg.norm(E - sign * result.lo_model, ord='fro') < 5e-2 assert correct_found == 1
def test_uniform_essential_ransac(one_pair_and_its_E): f1, f2, E, _ = one_pair_and_its_E points = np.concatenate((f1, f2), axis=1) scale = 1e-2 points += np.random.rand(*points.shape) * scale 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() result = pyrobust.ransac_essential(f1, f2, scale, params, pyrobust.RansacType.RANSAC) assert len(result.inliers_indices) == len(f1) == len(f2)
def test_uniform_essential_ransac(pairs_and_their_E): for f1, f2, E, _ in pairs_and_their_E: points = np.concatenate((f1, f2), axis=1) scale = 1e-2 points += np.random.rand(*points.shape) * scale 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 = 5e-1 params = pyrobust.RobustEstimatorParams() params.use_iteration_reduction = False result = pyrobust.ransac_essential(f1, f2, scale * (1.0 + scale_eps_ratio), params, pyrobust.RansacType.RANSAC) assert len(result.inliers_indices) == len(f1) == len(f2)