Loading autocnet/graph/network.py +35 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ from collections import Hashable import networkx as nx import pandas as pd import cv2 import numpy as np from autocnet.control.control import C, POINT_TYPE, MEASURE_TYPE from autocnet.fileio import io_json Loading Loading @@ -68,7 +70,6 @@ class CandidateGraph(nx.Graph): #TODO: This really belongs in an outlier detection matcher class, not here. # Remove erroneous self neighbors matches = matches.loc[matches['matched_to'] != source_node] groups = matches.groupby('matched_to') for destination_node, group in groups: try: Loading @@ -82,6 +83,39 @@ class CandidateGraph(nx.Graph): else: edge['matches'] = matches # deal with no edge case / fail better #document def compute_homography(self, source_key, destination_key, outlier_algorithm=cv2.RANSAC): 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(): # Get the source and destination x,y coordinates for matches source_idx = row['queryIdx_x'] src_keypoints = [self.node[source_key]['keypoints'][source_idx].pt[0], self.node[source_key]['keypoints'][source_idx].pt[1]] destination_idx = row['queryIdx_y'] #print(destination_idx) #print(len(self.node[destination_key]['keypoints'])) dest_keypoints = [self.node[destination_key]['keypoints'][destination_idx-1].pt[0], self.node[destination_key]['keypoints'][destination_idx-1].pt[1]] source_keypoints.append(src_keypoints) destination_keypoints.append(dest_keypoints) 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 @@ -95,7 +129,6 @@ class CandidateGraph(nx.Graph): point_ids = [] serials = [] for source, destination, attributes in self.edges_iter(data=True): for i, row in attributes['matches'].iterrows(): # Get the source and destination x,y coordinates for matches Loading functional_tests/test_two_image.py +6 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,11 @@ class TestTwoImageMatching(unittest.TestCase): ignoreme, matches = fl.query(descriptors, k=2) cg.add_matches(node, matches) #test new M, n = cg.compute_homography('AS15-M-0297_SML.png', 'AS15-M-0298_SML.png') print(M) #for me print(n) # for me # Step: And create a C object cnet = cg.to_cnet() Loading @@ -83,6 +88,7 @@ class TestTwoImageMatching(unittest.TestCase): cnet.index.set_levels(new_idx, inplace=True) self.assertTrue(False) #force test to fail # Step: Output a control network to_isis('TestTwoImageMatching.net', cnet, mode='wb', Loading Loading
autocnet/graph/network.py +35 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ from collections import Hashable import networkx as nx import pandas as pd import cv2 import numpy as np from autocnet.control.control import C, POINT_TYPE, MEASURE_TYPE from autocnet.fileio import io_json Loading Loading @@ -68,7 +70,6 @@ class CandidateGraph(nx.Graph): #TODO: This really belongs in an outlier detection matcher class, not here. # Remove erroneous self neighbors matches = matches.loc[matches['matched_to'] != source_node] groups = matches.groupby('matched_to') for destination_node, group in groups: try: Loading @@ -82,6 +83,39 @@ class CandidateGraph(nx.Graph): else: edge['matches'] = matches # deal with no edge case / fail better #document def compute_homography(self, source_key, destination_key, outlier_algorithm=cv2.RANSAC): 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(): # Get the source and destination x,y coordinates for matches source_idx = row['queryIdx_x'] src_keypoints = [self.node[source_key]['keypoints'][source_idx].pt[0], self.node[source_key]['keypoints'][source_idx].pt[1]] destination_idx = row['queryIdx_y'] #print(destination_idx) #print(len(self.node[destination_key]['keypoints'])) dest_keypoints = [self.node[destination_key]['keypoints'][destination_idx-1].pt[0], self.node[destination_key]['keypoints'][destination_idx-1].pt[1]] source_keypoints.append(src_keypoints) destination_keypoints.append(dest_keypoints) 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 @@ -95,7 +129,6 @@ class CandidateGraph(nx.Graph): point_ids = [] serials = [] for source, destination, attributes in self.edges_iter(data=True): for i, row in attributes['matches'].iterrows(): # Get the source and destination x,y coordinates for matches Loading
functional_tests/test_two_image.py +6 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,11 @@ class TestTwoImageMatching(unittest.TestCase): ignoreme, matches = fl.query(descriptors, k=2) cg.add_matches(node, matches) #test new M, n = cg.compute_homography('AS15-M-0297_SML.png', 'AS15-M-0298_SML.png') print(M) #for me print(n) # for me # Step: And create a C object cnet = cg.to_cnet() Loading @@ -83,6 +88,7 @@ class TestTwoImageMatching(unittest.TestCase): cnet.index.set_levels(new_idx, inplace=True) self.assertTrue(False) #force test to fail # Step: Output a control network to_isis('TestTwoImageMatching.net', cnet, mode='wb', Loading