def test_euclidean_estimation(): # exact solution tform = estimate_transform('euclidean', SRC[:2, :], SRC[:2, :] + 10) assert_almost_equal(tform(SRC[:2, :]), SRC[:2, :] + 10) assert_almost_equal(tform.params[0, 0], tform.params[1, 1]) assert_almost_equal(tform.params[0, 1], -tform.params[1, 0]) # over-determined tform2 = estimate_transform('euclidean', SRC, DST) assert_almost_equal(tform2.inverse(tform2(SRC)), SRC) assert_almost_equal(tform2.params[0, 0], tform2.params[1, 1]) assert_almost_equal(tform2.params[0, 1], -tform2.params[1, 0]) # via estimate method tform3 = EuclideanTransform() tform3.estimate(SRC, DST) assert_almost_equal(tform3.params, tform2.params)
def test_euclidean_estimation(): # exact solution tform = estimate_transform('euclidean', SRC[:2, :], SRC[:2, :] + 10) assert_almost_equal(tform(SRC[:2, :]), SRC[:2, :] + 10) assert_almost_equal(tform.params[0, 0], tform.params[1, 1]) assert_almost_equal(tform.params[0, 1], - tform.params[1, 0]) # over-determined tform2 = estimate_transform('euclidean', SRC, DST) assert_almost_equal(tform2.inverse(tform2(SRC)), SRC) assert_almost_equal(tform2.params[0, 0], tform2.params[1, 1]) assert_almost_equal(tform2.params[0, 1], - tform2.params[1, 0]) # via estimate method tform3 = EuclideanTransform() tform3.estimate(SRC, DST) assert_almost_equal(tform3.params, tform2.params)
def absolute_orientation(p, q, no_scaling=False): """ Returns R, t, s satisfying q = s * R * p + t p and q must be 3xN matrices. """ if no_scaling: st = EuclideanTransform() else: st = SimilarityTransform() st.estimate(p.T, q.T) R = st.params[:3, :3] t = st.params[:3, 3] s = np.linalg.norm(R) / np.sqrt(3) R = R / s return R, t, s
def transform_euclidean(left_kps, right_kps, left_ds, right_ds): """Determine projective transform which fits best to map right kps to left kps.""" bf = cv2.BFMatcher() log.info('Start matching Features.') raw_matches = bf.knnMatch(left_ds, right_ds, k=2) log.debug('Matches found: #raw_matches = {}'.format(len(raw_matches))) left_pts, right_pts, good_matches = helpers.get_points_n_matches( left_kps, right_kps, raw_matches) log.debug('# Filtered Features = {}'.format(len(good_matches))) if len(left_pts) > 3: log.info('Start finding homography.') left_pts = left_pts.reshape((len(left_pts), 2)) right_pts = right_pts.reshape((len(right_pts), 2)) model = EuclideanTransform() model.estimate(right_pts, left_pts) model_robust, inliers = ransac((right_pts, left_pts), EuclideanTransform, min_samples=50, residual_threshold=10, max_trials=3000) h**o = model_robust.params mask_good = None return h**o, mask_good, good_matches return None
def test_3d_euclidean_estimation(): src_points = np.random.rand(1000, 3) # Random transformation for testing angles = np.random.random((3, )) * 2 * np.pi - np.pi rotation_matrix = _euler_rotation_matrix(angles) translation_vector = np.random.random((3, )) dst_points = [] for pt in src_points: pt_r = pt.reshape(3, 1) dst = np.matmul(rotation_matrix, pt_r) + \ translation_vector.reshape(3, 1) dst = dst.reshape(3) dst_points.append(dst) dst_points = np.array(dst_points) # estimating the transformation tform = EuclideanTransform(dimensionality=3) assert tform.estimate(src_points, dst_points) estimated_rotation = tform.rotation estimated_translation = tform.translation assert_almost_equal(estimated_rotation, rotation_matrix) assert_almost_equal(estimated_translation, translation_vector)