Loading autocnet/graph/network.py +11 −1 Original line number Diff line number Diff line Loading @@ -237,7 +237,6 @@ class CandidateGraph(nx.Graph): transformation_matrix, ransac_mask = od.compute_homography(s_coords, d_coords) ransac_mask = ransac_mask.ravel() # Convert the truncated RANSAC mask back into a full length mask if clean_keys: Loading @@ -245,6 +244,17 @@ class CandidateGraph(nx.Graph): else: mask = ransac_mask # Compute the error in the homography s_trans = np.hstack((s_coords[::-1],np.ones(s_coords.shape[0]).reshape(-1,1))).T s_trans = np.dot(transformation_matrix, s_trans).T #Normalize the error for i in range(3): s_trans[i] /= s_trans[2] d_trans = np.hstack((d_coords[::-1], np.ones(d_coords.shape[0]).reshape(-1,1))) attributes['homography_error'] = np.sqrt(np.sum((d_trans - s_trans)**2, axis=1)) attributes['homography'] = transformation_matrix attributes['ransac'] = mask Loading autocnet/matcher/outlier_detector.py +33 −1 Original line number Diff line number Diff line Loading @@ -148,3 +148,35 @@ def compute_homography(kp1, kp2, outlier_algorithm=cv2.RANSAC, reproj_threshold= reproj_threshold) mask = mask.astype(bool) return transformation_matrix, mask def homography_test(kp1, kp2, homography, threshold=3.0): """ Utilize the transformation matrix (homography) to check whether keypoint one (`kp1`) to keypoint two (`kp2`). If the point is within threshold units (where the unit is agnositic and a function of the image pixel size) return true. Parameters ---------- kp1 : list of x, y coordinates kp2 : list of x, y coordinates homography : ndarray 3x3 transformation matrix threshold : float The threshold within which true is returned Returns ------- : bool True if within the threshold, else False """ kp1 = kp1[::-1] kp2 = kp2[::-1] kp1 = np.array([*kp1, 1]) kp2 = np.array([*kp2, 1]) print(kp1, np.dot(kp1, homography), kp2) functional_tests/test_two_image.py +1 −1 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ class TestTwoImageMatching(unittest.TestCase): # Perform the ratio test ratio_mask = od.distance_ratio(matches, ratio=0.95) self.assertIn(ratio_mask.sum(), range(400, 451)) self.assertIn(ratio_mask.sum(), range(390, 451)) attributes['ratio'] = ratio_mask mask = np.array(ratio_mask * symmetry_mask) Loading Loading
autocnet/graph/network.py +11 −1 Original line number Diff line number Diff line Loading @@ -237,7 +237,6 @@ class CandidateGraph(nx.Graph): transformation_matrix, ransac_mask = od.compute_homography(s_coords, d_coords) ransac_mask = ransac_mask.ravel() # Convert the truncated RANSAC mask back into a full length mask if clean_keys: Loading @@ -245,6 +244,17 @@ class CandidateGraph(nx.Graph): else: mask = ransac_mask # Compute the error in the homography s_trans = np.hstack((s_coords[::-1],np.ones(s_coords.shape[0]).reshape(-1,1))).T s_trans = np.dot(transformation_matrix, s_trans).T #Normalize the error for i in range(3): s_trans[i] /= s_trans[2] d_trans = np.hstack((d_coords[::-1], np.ones(d_coords.shape[0]).reshape(-1,1))) attributes['homography_error'] = np.sqrt(np.sum((d_trans - s_trans)**2, axis=1)) attributes['homography'] = transformation_matrix attributes['ransac'] = mask Loading
autocnet/matcher/outlier_detector.py +33 −1 Original line number Diff line number Diff line Loading @@ -148,3 +148,35 @@ def compute_homography(kp1, kp2, outlier_algorithm=cv2.RANSAC, reproj_threshold= reproj_threshold) mask = mask.astype(bool) return transformation_matrix, mask def homography_test(kp1, kp2, homography, threshold=3.0): """ Utilize the transformation matrix (homography) to check whether keypoint one (`kp1`) to keypoint two (`kp2`). If the point is within threshold units (where the unit is agnositic and a function of the image pixel size) return true. Parameters ---------- kp1 : list of x, y coordinates kp2 : list of x, y coordinates homography : ndarray 3x3 transformation matrix threshold : float The threshold within which true is returned Returns ------- : bool True if within the threshold, else False """ kp1 = kp1[::-1] kp2 = kp2[::-1] kp1 = np.array([*kp1, 1]) kp2 = np.array([*kp2, 1]) print(kp1, np.dot(kp1, homography), kp2)
functional_tests/test_two_image.py +1 −1 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ class TestTwoImageMatching(unittest.TestCase): # Perform the ratio test ratio_mask = od.distance_ratio(matches, ratio=0.95) self.assertIn(ratio_mask.sum(), range(400, 451)) self.assertIn(ratio_mask.sum(), range(390, 451)) attributes['ratio'] = ratio_mask mask = np.array(ratio_mask * symmetry_mask) Loading