def absolute_pose_ransac(bs, Xs, method, threshold, iterations, probabilty): # in-house estimation if in_house_multiview: threshold = np.arccos(1 - threshold) params = pyrobust.RobustEstimatorParams() params.iterations = 1000 result = pyrobust.ransac_absolute_pose(bs, Xs, 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 else: try: return pyopengv.absolute_pose_ransac(bs, Xs, method, threshold, iterations=iterations, probabilty=probabilty) except Exception: # Older versions of pyopengv do not accept the probability argument. return pyopengv.absolute_pose_ransac(bs, Xs, method, threshold, iterations)
def test_outliers_absolute_pose_ransac(one_shot_and_its_points): pose, bearings, points = one_shot_and_its_points scale = 1e-3 bearings = copy.deepcopy(bearings) bearings += np.random.rand(*bearings.shape) * scale ratio_outliers = 0.3 add_outliers(ratio_outliers, bearings, 0.1, 1.0) bearings /= np.linalg.norm(bearings, axis=1)[:, None] params = pyrobust.RobustEstimatorParams() params.iterations = 1000 result = pyrobust.ransac_absolute_pose(bearings, points, scale, params, pyrobust.RansacType.RANSAC) expected = pose.get_Rt() tolerance = 0.05 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
def absolute_pose_ransac(bs, Xs, threshold, iterations, probabilty): params = pyrobust.RobustEstimatorParams() params.iterations = 1000 result = pyrobust.ransac_absolute_pose(bs, Xs, 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
def absolute_pose_ransac( bs: np.ndarray, Xs: np.ndarray, threshold: float, iterations: int, probability: float, ) -> np.ndarray: params = pyrobust.RobustEstimatorParams() params.iterations = iterations result = pyrobust.ransac_absolute_pose(bs, Xs, 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