Loading autocnet/matcher/feature_extractor.py +9 −9 Original line number Diff line number Diff line import cv2 from scipy import misc def extract_features(image_array, num_nodes=500): def extract_features(image_array, extractor_parameters): """ Extracts keypoints and corresponding descriptors from a numpy array that represents an image. The extracted information is returned as a tuple whose first element is a list of KeyPoints and whose second element is a numpy array of geometric vector descriptors. This method finds and extracts features from an image using the given dictionary of keyword arguments. The input image is represented as NumPy array and the output features are represented as keypoint IDs with corresponding descriptors. Parameters ---------- image_array : ndarray a numpy array that represents an image num_nodes : int the number of best features to retain a NumPy array that represents an image extractor_parameters : dict A dictionary containing OpenCV SIFT parameters names and values. Returns ------- : tuple This tuple is in the form (list of KeyPoints, array of descriptors) in the form ([list of OpenCV KeyPoints], [NumPy array of descriptors as geometric vectors]) """ sift = cv2.xfeatures2d.SIFT_create(num_nodes) sift = cv2.xfeatures2d.SIFT_create(**extractor_parameters) converted_array = misc.bytescale(image_array) return sift.detectAndCompute(converted_array, None) autocnet/matcher/tests/test_feature_extractor.py +6 −1 Original line number Diff line number Diff line Loading @@ -15,9 +15,14 @@ class TestFeatureExtractor(unittest.TestCase): def setUp(self): self.dataset = io_gdal.GeoDataset(get_path('Mars_MGS_MOLA_ClrShade_MAP2_0.0N0.0_MERC.tif')) self.data_array = self.dataset.read_array() self.parameters = {"nfeatures" : 10, "nOctaveLayers" : 3, "contrastThreshold" : 0.02, "edgeThreshold" : 10, "sigma" : 1.6} def test_extract_features(self): features = feature_extractor.extract_features(self.data_array, 10) features = feature_extractor.extract_features(self.data_array, self.parameters) self.assertEquals(len(features), 2) self.assertIsInstance(features[0][0], type(cv2.KeyPoint())) self.assertIsInstance(features[1][0], np.ndarray) Loading Loading
autocnet/matcher/feature_extractor.py +9 −9 Original line number Diff line number Diff line import cv2 from scipy import misc def extract_features(image_array, num_nodes=500): def extract_features(image_array, extractor_parameters): """ Extracts keypoints and corresponding descriptors from a numpy array that represents an image. The extracted information is returned as a tuple whose first element is a list of KeyPoints and whose second element is a numpy array of geometric vector descriptors. This method finds and extracts features from an image using the given dictionary of keyword arguments. The input image is represented as NumPy array and the output features are represented as keypoint IDs with corresponding descriptors. Parameters ---------- image_array : ndarray a numpy array that represents an image num_nodes : int the number of best features to retain a NumPy array that represents an image extractor_parameters : dict A dictionary containing OpenCV SIFT parameters names and values. Returns ------- : tuple This tuple is in the form (list of KeyPoints, array of descriptors) in the form ([list of OpenCV KeyPoints], [NumPy array of descriptors as geometric vectors]) """ sift = cv2.xfeatures2d.SIFT_create(num_nodes) sift = cv2.xfeatures2d.SIFT_create(**extractor_parameters) converted_array = misc.bytescale(image_array) return sift.detectAndCompute(converted_array, None)
autocnet/matcher/tests/test_feature_extractor.py +6 −1 Original line number Diff line number Diff line Loading @@ -15,9 +15,14 @@ class TestFeatureExtractor(unittest.TestCase): def setUp(self): self.dataset = io_gdal.GeoDataset(get_path('Mars_MGS_MOLA_ClrShade_MAP2_0.0N0.0_MERC.tif')) self.data_array = self.dataset.read_array() self.parameters = {"nfeatures" : 10, "nOctaveLayers" : 3, "contrastThreshold" : 0.02, "edgeThreshold" : 10, "sigma" : 1.6} def test_extract_features(self): features = feature_extractor.extract_features(self.data_array, 10) features = feature_extractor.extract_features(self.data_array, self.parameters) self.assertEquals(len(features), 2) self.assertIsInstance(features[0][0], type(cv2.KeyPoint())) self.assertIsInstance(features[1][0], np.ndarray) Loading