-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature_extractor.py
89 lines (68 loc) · 2.52 KB
/
feature_extractor.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import cv2
# import fhog_feature
# import cn_feature
import numpy as np
import conv_reg_config
class FeatureExtractor(object):
def __init__(self):
self._resolution = 1.0
self._channel_num = 1
def _extract_feature(self, image):
pass
def extract_multiple_features(self, input_images):
features = []
for image in input_images:
feature = self._extract_feature(image)
features.append(feature[np.newaxis, :, :, :])
assert len(features) > 0
conca_features = np.concatenate(features, axis=0)
return conca_features
def get_resolution(self):
return self._resolution
def get_channel_num(self):
return self._channel_num
class GrayExtractor(FeatureExtractor):
def _extract_feature(self, input_image):
gray = cv2.cvtColor(input_image, cv2.COLOR_RGB2GRAY)
return gray
class RgbExtractor(FeatureExtractor):
def __init__(self):
super(RgbExtractor, self).__init__()
self._channel_num = 3
def _extract_feature(self, input_image):
return input_image
# class FhogExtractor(FeatureExtractor):
#
# def __init__(self):
# super(FhogExtractor, self).__init__()
# self.cell_size = conv_reg_config.FhogCfg.CELL_SIZE
# self.bin_num = conv_reg_config.FhogCfg.BIN_NUM
# self._resolution = self.cell_size
# self._channel_num = 3*self.bin_num + 4
#
# def _extract_feature(self, input_image):
# assert input_image.shape[2] == 3
# im = cv2.cvtColor(input_image, cv2.COLOR_BGR2GRAY)
# im = np.asarray(im, dtype=np.float32)
# return fhog_feature.extract(im, bin_size=self.cell_size, n_orients=self.bin_num)
#
# class FhogCnExtractor(FeatureExtractor):
#
# def __init__(self):
# super(FhogCnExtractor, self).__init__()
# self.cell_size = conv_reg_config.FhogCnCfg.CELL_SIZE
# self.bin_num = conv_reg_config.FhogCnCfg.BIN_NUM
# self._resolution = self.cell_size
# self._channel_num = 3*self.bin_num + 4 + 10
#
# def _extract_feature(self, input_image):
# assert input_image.shape[2] == 3
# im = cv2.cvtColor(input_image, cv2.COLOR_BGR2GRAY)
# im = np.asarray(im, dtype=np.float32)
# fhog = fhog_feature.extract(im, bin_size=self.cell_size, n_orients=self.bin_num)
#
# rescaled_im = cv2.resize(input_image, (fhog.shape[1], fhog.shape[0]))
# cn = cn_feature.extract(rescaled_im)
#
# res = np.concatenate((fhog, cn), axis=2)
# return res