-
Notifications
You must be signed in to change notification settings - Fork 337
/
test_feature_manager.py
76 lines (52 loc) · 2.29 KB
/
test_feature_manager.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
#!/usr/bin/env -S python3 -O
import sys
import numpy as np
import cv2
from matplotlib import pyplot as plt
sys.path.append("../../")
from config import Config
from mplot_figure import MPlotFigure
from feature_manager import feature_manager_factory
from feature_types import FeatureDetectorTypes, FeatureDescriptorTypes, FeatureInfo
from utils_features import ssc_nms
from collections import defaultdict, Counter
from feature_manager_configs import FeatureManagerConfigs
from feature_tracker_configs import FeatureTrackerConfigs
from timer import TimerFps
# ==================================================================================================
# N.B.: here we test feature manager detectAndCompute()
# ==================================================================================================
timer = TimerFps()
#img = cv2.imread('../data/kitti06-12.png',cv2.IMREAD_COLOR)
#img = cv2.imread('../data/kitti06-435.png',cv2.IMREAD_COLOR)
img = cv2.imread('../data/kitti06-12-color.png',cv2.IMREAD_COLOR)
#img = cv2.imread('../data/mars1.png')
num_features=2000
# select your tracker configuration (see the file feature_tracker_configs.py)
feature_tracker_config = FeatureTrackerConfigs.TEST
feature_tracker_config['num_features'] = num_features
feature_manager_config = FeatureManagerConfigs.extract_from(feature_tracker_config)
print('feature_manager_config: ',feature_manager_config)
feature_manager = feature_manager_factory(**feature_manager_config)
des = None
# loop for measuring time performance
N=20
for i in range(N):
timer.start()
# just detect keypoints
#kps = feature_manager.detect(img)
# detect keypoints and compute descriptors
kps, des = feature_manager.detectAndCompute(img)
timer.refresh()
#sizes = np.array([x.size for x in kps], dtype=np.float32)
print('#kps: ', len(kps))
if des is not None:
print('des shape: ', des.shape)
#print('octaves: ', [p.octave for p in kps])
# count points for each octave
kps_octaves = [k.octave for k in kps]
kps_octaves = Counter(kps_octaves)
print('kps levels-histogram: \n', kps_octaves.most_common())
imgDraw = cv2.drawKeypoints(img, kps, None, color=(0,255,0), flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
fig = MPlotFigure(imgDraw[:,:,[2,1,0]], title='features')
MPlotFigure.show()