Loading autocnet/graph/network.py +45 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ import os import networkx as nx import pandas as pd import cv2 import numpy as np from autocnet.control.control import C from autocnet.fileio import io_json Loading Loading @@ -92,6 +94,49 @@ class CandidateGraph(nx.Graph): else: edge['matches'] = dest_group def compute_homography(self, source_key, destination_key, outlier_algorithm=cv2.RANSAC): """ Parameters ---------- source_key : str The identifier for the source node destination_key : str The identifier for the destination node Returns ------- : tuple A tuple of the form (transformation matrix, bad entry mask) The returned tuple is empty if there is no edge between the source and destination nodes or if it exists, but has not been populated with a matches dataframe. """ if self.has_edge(source_key, destination_key): try: edge = self[source_key][destination_key] except: edge = self[destination_key][source_key] if 'matches' in edge.keys(): source_keypoints = [] destination_keypoints = [] for i, row in edge['matches'].iterrows(): source_idx = row['source_idx'] src_keypoint = [self.node[source_key]['keypoints'][int(source_idx)].pt[0], self.node[source_key]['keypoints'][int(source_idx)].pt[1]] destination_idx = row['destination_idx'] dest_keypoint = [self.node[destination_key]['keypoints'][int(destination_idx)].pt[0], self.node[destination_key]['keypoints'][int(destination_idx)].pt[1]] source_keypoints.append(src_keypoint) destination_keypoints.append(dest_keypoint) return cv2.findHomography(np.array(source_keypoints), np.array(destination_keypoints), outlier_algorithm, 5.0) else: return ('', '') else: return ('','') def to_cnet(self): """ Generate a control network (C) object from a graph Loading autocnet/matcher/tests/test_feature_extractor.py +1 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ class TestFeatureExtractor(unittest.TestCase): def test_extract_features(self): features = feature_extractor.extract_features(self.data_array, self.parameters) self.assertEquals(len(features), 2) self.assertEqual(len(features[0]), 10) # OpenCV +1 to self.assertEqual(len(features[0]), 11) # OpenCV +1 to self.assertIsInstance(features[0][0], type(cv2.KeyPoint())) self.assertIsInstance(features[1][0], np.ndarray) functional_tests/test_two_image.py +7 −2 Original line number Diff line number Diff line import os import unittest import pandas as pd from scipy.misc import bytescale from autocnet.examples import get_path Loading Loading @@ -67,9 +66,15 @@ class TestTwoImageMatching(unittest.TestCase): for node, attributes in cg.nodes_iter(data=True): descriptors = attributes['descriptors'] matches = fl.query(descriptors, node, k=2) matches = fl.query(descriptors, node, k=3) cg.add_matches(matches) # Step: Compute Homography transformation_matrix, mask = cg.compute_homography(0, 1) self.assertEquals(len(transformation_matrix), 3) #TODO: write better test #self.assertEquals(len(mask), 19) # Step: And create a C object cnet = cg.to_cnet() Loading autocnet/matcher/tests/test_matcher.py +1 −1 File changed.Contains only whitespace changes. Show changes Loading
autocnet/graph/network.py +45 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ import os import networkx as nx import pandas as pd import cv2 import numpy as np from autocnet.control.control import C from autocnet.fileio import io_json Loading Loading @@ -92,6 +94,49 @@ class CandidateGraph(nx.Graph): else: edge['matches'] = dest_group def compute_homography(self, source_key, destination_key, outlier_algorithm=cv2.RANSAC): """ Parameters ---------- source_key : str The identifier for the source node destination_key : str The identifier for the destination node Returns ------- : tuple A tuple of the form (transformation matrix, bad entry mask) The returned tuple is empty if there is no edge between the source and destination nodes or if it exists, but has not been populated with a matches dataframe. """ if self.has_edge(source_key, destination_key): try: edge = self[source_key][destination_key] except: edge = self[destination_key][source_key] if 'matches' in edge.keys(): source_keypoints = [] destination_keypoints = [] for i, row in edge['matches'].iterrows(): source_idx = row['source_idx'] src_keypoint = [self.node[source_key]['keypoints'][int(source_idx)].pt[0], self.node[source_key]['keypoints'][int(source_idx)].pt[1]] destination_idx = row['destination_idx'] dest_keypoint = [self.node[destination_key]['keypoints'][int(destination_idx)].pt[0], self.node[destination_key]['keypoints'][int(destination_idx)].pt[1]] source_keypoints.append(src_keypoint) destination_keypoints.append(dest_keypoint) return cv2.findHomography(np.array(source_keypoints), np.array(destination_keypoints), outlier_algorithm, 5.0) else: return ('', '') else: return ('','') def to_cnet(self): """ Generate a control network (C) object from a graph Loading
autocnet/matcher/tests/test_feature_extractor.py +1 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ class TestFeatureExtractor(unittest.TestCase): def test_extract_features(self): features = feature_extractor.extract_features(self.data_array, self.parameters) self.assertEquals(len(features), 2) self.assertEqual(len(features[0]), 10) # OpenCV +1 to self.assertEqual(len(features[0]), 11) # OpenCV +1 to self.assertIsInstance(features[0][0], type(cv2.KeyPoint())) self.assertIsInstance(features[1][0], np.ndarray)
functional_tests/test_two_image.py +7 −2 Original line number Diff line number Diff line import os import unittest import pandas as pd from scipy.misc import bytescale from autocnet.examples import get_path Loading Loading @@ -67,9 +66,15 @@ class TestTwoImageMatching(unittest.TestCase): for node, attributes in cg.nodes_iter(data=True): descriptors = attributes['descriptors'] matches = fl.query(descriptors, node, k=2) matches = fl.query(descriptors, node, k=3) cg.add_matches(matches) # Step: Compute Homography transformation_matrix, mask = cg.compute_homography(0, 1) self.assertEquals(len(transformation_matrix), 3) #TODO: write better test #self.assertEquals(len(mask), 19) # Step: And create a C object cnet = cg.to_cnet() Loading
autocnet/matcher/tests/test_matcher.py +1 −1 File changed.Contains only whitespace changes. Show changes