Loading autocnet/matcher/feature_extractor.py +22 −2 Original line number Diff line number Diff line def extract_features(): #stuff import cv2 def extract_features(image_array, num_nodes=500): """ 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. Parameters ---------- image_array : ndarray a numpy array that represents an image num_nodes : int the number of best features to retain Returns ------- : tuple This tuple is in the form (list of KeyPoints, array of descriptors) """ sift = cv2.xfeatures2d.SIFT_create(num_nodes) return sift.detectAndCompute(image_array, None) No newline at end of file autocnet/matcher/tests/test_feature_extractor.py +25 −0 Original line number Diff line number Diff line import os import numpy as np import unittest from scipy.misc import bytescale from autocnet.examples import get_path import cv2 import sys sys.path.insert(0, os.path.abspath('..')) from .. import feature_extractor from autocnet.fileio import io_gdal 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 = bytescale(self.dataset.read_array()) def test_extract_features(self): features = feature_extractor.extract_features(self.data_array, 10) self.assertEquals(len(features), 2) self.assertIsInstance(features[0][0], type(cv2.KeyPoint())) self.assertIsInstance(features[1][0], np.ndarray) Loading
autocnet/matcher/feature_extractor.py +22 −2 Original line number Diff line number Diff line def extract_features(): #stuff import cv2 def extract_features(image_array, num_nodes=500): """ 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. Parameters ---------- image_array : ndarray a numpy array that represents an image num_nodes : int the number of best features to retain Returns ------- : tuple This tuple is in the form (list of KeyPoints, array of descriptors) """ sift = cv2.xfeatures2d.SIFT_create(num_nodes) return sift.detectAndCompute(image_array, None) No newline at end of file
autocnet/matcher/tests/test_feature_extractor.py +25 −0 Original line number Diff line number Diff line import os import numpy as np import unittest from scipy.misc import bytescale from autocnet.examples import get_path import cv2 import sys sys.path.insert(0, os.path.abspath('..')) from .. import feature_extractor from autocnet.fileio import io_gdal 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 = bytescale(self.dataset.read_array()) def test_extract_features(self): features = feature_extractor.extract_features(self.data_array, 10) self.assertEquals(len(features), 2) self.assertIsInstance(features[0][0], type(cv2.KeyPoint())) self.assertIsInstance(features[1][0], np.ndarray)