Loading autocnet/graph/edge.py +12 −18 Original line number Diff line number Diff line Loading @@ -487,6 +487,13 @@ class Edge(dict, MutableMapping): self.weight['overlap_area'] = overlapinfo[1] self.weight['overlap_percn'] = overlapinfo[0] def _construct_json_serial(self, coords): hull = cg.convex_hull(coords) poly_points = [hull.points[i] for i in hull.vertices] coordinates = [[i, j] for [i, j] in poly_points] coordinates.append((poly_points[0][0], poly_points[0][1])) return coordinates def coverage(self, image='source'): mask = self.masks.all(axis = 1) matches = self.matches[mask] Loading @@ -495,23 +502,14 @@ class Edge(dict, MutableMapping): source_array = [self.source.get_keypoint_coordinates(i) for i in df_source_array] destination_array = [self.destination.get_keypoint_coordinates(i) for i in df_destination_array] source_points = np.array(source_array) destination_points = np.array(destination_array) source_verts = self.source.geodata.latlon_corners destination_verts = self.destination.geodata.latlon_corners # Generate the latlon cords for the source node source_hull = cg.convex_hull(source_verts) source_poly_points = [source_hull.points[i] for i in source_hull.vertices] source_coords = [[i, j] for [i, j] in source_poly_points] source_coords.append((source_poly_points[0][0], source_poly_points[0][1])) source_coordinates = self._construct_json_serial(source_verts) # Generate the latlon cords for the destination node destination_hull = cg.convex_hull(destination_verts) destination_poly_points = [destination_hull.points[i] for i in destination_hull.vertices] destination_coords = [[i, j] for [i, j] in destination_poly_points] destination_coords.append((destination_poly_points[0][0], destination_poly_points[0][1])) destination_coordinates = self._construct_json_serial(destination_verts) if image == 'source': image_covered = source_points Loading @@ -520,11 +518,7 @@ class Edge(dict, MutableMapping): image_covered = destination_points node = self.destination # Generate the pixel points for the convex hull convex_hull = cg.convex_hull(image_covered) convex_pixel_points = [convex_hull.points[i] for i in convex_hull.vertices] convex_coordinates = [[i, j] for [i, j] in convex_pixel_points] convex_coordinates.append(([convex_pixel_points[0][0], convex_pixel_points[0][1]])) convex_coordinates = self._construct_json_serial(image_covered) # Convert the convex hull pixel coordinates to latlon # coordinates Loading @@ -534,8 +528,8 @@ class Edge(dict, MutableMapping): convex_points.append(point) convex_coords = [[i, j] for i, j in convex_points] source_geom = {"type": "Polygon", "coordinates": [source_coords]} destination_geom = {"type": "Polygon", "coordinates": [destination_coords]} source_geom = {"type": "Polygon", "coordinates": [source_coordinates]} destination_geom = {"type": "Polygon", "coordinates": [destination_coordinates]} convex_geom = {"type": "Polygon", "coordinates": [convex_coords]} source_hull_poly = ogr.CreateGeometryFromJson(json.dumps(source_geom)) Loading autocnet/graph/tests/test_edge.py +24 −21 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ import unittest import ogr from unittest.mock import Mock from unittest.mock import MagicMock from autocnet.fileio import io_gdal from autocnet.examples import get_path Loading Loading @@ -76,24 +77,26 @@ class TestEdge(unittest.TestCase): self.assertAlmostEqual(e.weight['overlap_percn'], 14.285714285) def test_coverage(self): adjacency = get_path('geo_adjacancey.json') basepath = get_path('Apollo15') cg = CandidateGraph.from_adjacency(adjacency, basepath=basepath) #Apply SIFT to extract features cg.extract_features(method='sift', extractor_parameters={'nfeatures':500}) #Match cg.match_features() #Apply outlier detection cg.apply_func_to_edges('symmetry_check') cg.apply_func_to_edges('ratio_check') #Compute a homography and apply RANSAC cg.apply_func_to_edges("compute_fundamental_matrix", clean_keys=['ratio', 'symmetry']) source_coverage = cg.edge[0][1].coverage(image = 'source') destination_coverage = cg.edge[0][1].coverage(image = 'destination') print() self.assertTrue() df1 = pd.DataFrame({'x': (15, 18, 18, 12, 12), 'y': (5, 10, 15, 15, 10)}) array1 = [True, True, True, True, True] array2 = [[0, 0, 1, 0], [0, 1, 1, 1], [0, 2, 1, 2], [0, 3, 1, 3], [0, 4, 1, 4]] df2 = pd.DataFrame(data = array1, columns = ['symmetry'], dtype = bool) df3 = pd.DataFrame(data = array2, columns = ['source_image', 'source_idx', 'destination_image', 'destination_idx'] ) e = Mock(spec = edge.Edge()) source_node = node.Node() destination_node = node.Node() source_node.get_keypoint_coordinates = MagicMock(return_value=df1) destination_node.get_keypoint_coordinates = MagicMock(return_value=df1) e.source = source_node e.destination = destination_node e.matches = df3 # e.masks = df2 e.coverage(image = 'source') No newline at end of file Loading
autocnet/graph/edge.py +12 −18 Original line number Diff line number Diff line Loading @@ -487,6 +487,13 @@ class Edge(dict, MutableMapping): self.weight['overlap_area'] = overlapinfo[1] self.weight['overlap_percn'] = overlapinfo[0] def _construct_json_serial(self, coords): hull = cg.convex_hull(coords) poly_points = [hull.points[i] for i in hull.vertices] coordinates = [[i, j] for [i, j] in poly_points] coordinates.append((poly_points[0][0], poly_points[0][1])) return coordinates def coverage(self, image='source'): mask = self.masks.all(axis = 1) matches = self.matches[mask] Loading @@ -495,23 +502,14 @@ class Edge(dict, MutableMapping): source_array = [self.source.get_keypoint_coordinates(i) for i in df_source_array] destination_array = [self.destination.get_keypoint_coordinates(i) for i in df_destination_array] source_points = np.array(source_array) destination_points = np.array(destination_array) source_verts = self.source.geodata.latlon_corners destination_verts = self.destination.geodata.latlon_corners # Generate the latlon cords for the source node source_hull = cg.convex_hull(source_verts) source_poly_points = [source_hull.points[i] for i in source_hull.vertices] source_coords = [[i, j] for [i, j] in source_poly_points] source_coords.append((source_poly_points[0][0], source_poly_points[0][1])) source_coordinates = self._construct_json_serial(source_verts) # Generate the latlon cords for the destination node destination_hull = cg.convex_hull(destination_verts) destination_poly_points = [destination_hull.points[i] for i in destination_hull.vertices] destination_coords = [[i, j] for [i, j] in destination_poly_points] destination_coords.append((destination_poly_points[0][0], destination_poly_points[0][1])) destination_coordinates = self._construct_json_serial(destination_verts) if image == 'source': image_covered = source_points Loading @@ -520,11 +518,7 @@ class Edge(dict, MutableMapping): image_covered = destination_points node = self.destination # Generate the pixel points for the convex hull convex_hull = cg.convex_hull(image_covered) convex_pixel_points = [convex_hull.points[i] for i in convex_hull.vertices] convex_coordinates = [[i, j] for [i, j] in convex_pixel_points] convex_coordinates.append(([convex_pixel_points[0][0], convex_pixel_points[0][1]])) convex_coordinates = self._construct_json_serial(image_covered) # Convert the convex hull pixel coordinates to latlon # coordinates Loading @@ -534,8 +528,8 @@ class Edge(dict, MutableMapping): convex_points.append(point) convex_coords = [[i, j] for i, j in convex_points] source_geom = {"type": "Polygon", "coordinates": [source_coords]} destination_geom = {"type": "Polygon", "coordinates": [destination_coords]} source_geom = {"type": "Polygon", "coordinates": [source_coordinates]} destination_geom = {"type": "Polygon", "coordinates": [destination_coordinates]} convex_geom = {"type": "Polygon", "coordinates": [convex_coords]} source_hull_poly = ogr.CreateGeometryFromJson(json.dumps(source_geom)) Loading
autocnet/graph/tests/test_edge.py +24 −21 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ import unittest import ogr from unittest.mock import Mock from unittest.mock import MagicMock from autocnet.fileio import io_gdal from autocnet.examples import get_path Loading Loading @@ -76,24 +77,26 @@ class TestEdge(unittest.TestCase): self.assertAlmostEqual(e.weight['overlap_percn'], 14.285714285) def test_coverage(self): adjacency = get_path('geo_adjacancey.json') basepath = get_path('Apollo15') cg = CandidateGraph.from_adjacency(adjacency, basepath=basepath) #Apply SIFT to extract features cg.extract_features(method='sift', extractor_parameters={'nfeatures':500}) #Match cg.match_features() #Apply outlier detection cg.apply_func_to_edges('symmetry_check') cg.apply_func_to_edges('ratio_check') #Compute a homography and apply RANSAC cg.apply_func_to_edges("compute_fundamental_matrix", clean_keys=['ratio', 'symmetry']) source_coverage = cg.edge[0][1].coverage(image = 'source') destination_coverage = cg.edge[0][1].coverage(image = 'destination') print() self.assertTrue() df1 = pd.DataFrame({'x': (15, 18, 18, 12, 12), 'y': (5, 10, 15, 15, 10)}) array1 = [True, True, True, True, True] array2 = [[0, 0, 1, 0], [0, 1, 1, 1], [0, 2, 1, 2], [0, 3, 1, 3], [0, 4, 1, 4]] df2 = pd.DataFrame(data = array1, columns = ['symmetry'], dtype = bool) df3 = pd.DataFrame(data = array2, columns = ['source_image', 'source_idx', 'destination_image', 'destination_idx'] ) e = Mock(spec = edge.Edge()) source_node = node.Node() destination_node = node.Node() source_node.get_keypoint_coordinates = MagicMock(return_value=df1) destination_node.get_keypoint_coordinates = MagicMock(return_value=df1) e.source = source_node e.destination = destination_node e.matches = df3 # e.masks = df2 e.coverage(image = 'source') No newline at end of file