-
-
Notifications
You must be signed in to change notification settings - Fork 513
Expand file tree
/
Copy pathtest_feature_manager.py
More file actions
88 lines (61 loc) · 2.71 KB
/
test_feature_manager.py
File metadata and controls
88 lines (61 loc) · 2.71 KB
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
88
#!/usr/bin/env -S python3 -O
import sys
import numpy as np
import cv2
from matplotlib import pyplot as plt
from pyslam.config import Config
from pyslam.viz.mplot_figure import MPlotFigure
from pyslam.local_features.feature_manager import feature_manager_factory
from pyslam.local_features.feature_types import (
FeatureDetectorTypes,
FeatureDescriptorTypes,
FeatureInfo,
)
from pyslam.utilities.features import ssc_nms
from collections import defaultdict, Counter
from pyslam.local_features.feature_manager_configs import FeatureManagerConfigs
from pyslam.local_features.feature_tracker_configs import FeatureTrackerConfigs
from pyslam.utilities.timer import TimerFps
from pyslam.local_features.feature_keynet import KeyNetDescFeature2D
# ==================================================================================================
# 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)
# FeatureTrackerConfigs: SHI_TOMASI_ORB, FAST_ORB, ORB, ORB2, ORB2_FREAK, ORB2_BEBLID, BRISK, AKAZE, FAST_FREAK, SIFT, ROOT_SIFT, SURF, KEYNET, SUPERPOINT, CONTEXTDESC, LIGHTGLUE, XFEAT, XFEAT_XFEAT
feature_tracker_config = FeatureTrackerConfigs.ROOT_SIFT
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
img_old = img.copy()
# loop for measuring time performance
N = 1
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))
des = np.array(des)
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()