-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfeatureExtractor.py
39 lines (31 loc) · 1.32 KB
/
featureExtractor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import cv2
import numpy as np
FETURE_EXTRACTORS = ['SIFT']
class FeatureExtractor:
def __init__(self, src, algorithm, args):
self.common_args = {
'SIFT_nfeatures': args.SIFT_nfeatures,
'SIFT_nOctaveLayers': args.SIFT_nOctaveLayers,
'SIFT_contrastThreshold': args.SIFT_contrastThreshold,
'SIFT_edgeThreshold': args.SIFT_edgeThreshold,
'SIFT_sigma': args.SIFT_sigma
}
self._extractor = self._select_algorithm(algorithm)
self._src_image = src
def _select_algorithm(self, algorithm):
assert(algorithm in FETURE_EXTRACTORS)
if(algorithm == 'SIFT'):
return cv2.xfeatures2d.SIFT_create(
nfeatures=self.common_args['SIFT_nfeatures'],
nOctaveLayers=self.common_args['SIFT_nOctaveLayers'],
contrastThreshold=self.common_args['SIFT_contrastThreshold'],
edgeThreshold=self.common_args['SIFT_edgeThreshold'],
sigma=self.common_args['SIFT_sigma']
)
def compute(self, mask=None):
print(mask.shape)
print(np.max(mask))
self.features, self.descriptors = self._extractor.detectAndCompute(
self._src_image, mask)
def get_features_and_descriptors(self):
return self.features, self.descriptors