forked from luigifreda/pyslam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_orbslam2.py
59 lines (48 loc) · 2.15 KB
/
feature_orbslam2.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
"""
* This file is part of PYSLAM
*
* Copyright (C) 2016-present Luigi Freda <luigi dot freda at gmail dot com>
*
* PYSLAM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PYSLAM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PYSLAM. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import cv2
import numpy as np
from utils import Printer,getchar
from orbslam2_features import ORBextractor
kVerbose = True
# interface for pySLAM
class Orbslam2Feature2D:
def __init__(self,num_features=2000, scale_factor=1.2, num_levels=8):
print('Using Orbslam2Feature2D')
self.orb_extractor = ORBextractor(num_features, scale_factor, num_levels)
# extract keypoints
def detect(self, img, mask=None): #mask is fake: it is not considered by the c++ implementation
# detect and compute
kps_tuples = self.orb_extractor.detect(img)
# convert keypoints
kps = [cv2.KeyPoint(*kp) for kp in kps_tuples]
return kps
def compute(self, img, kps, mask=None):
Printer.orange('WARNING: you are supposed to call detectAndCompute() for ORB2 instead of compute()')
Printer.orange('WARNING: ORB2 is recomputing both kps and des on input frame', img.shape)
return self.detectAndCompute(img)
#return kps, np.array([])
# compute both keypoints and descriptors
def detectAndCompute(self, img, mask=None): #mask is fake: it is not considered by the c++ implementation
# detect and compute
kps_tuples, des = self.orb_extractor.detectAndCompute(img)
# convert keypoints
kps = [cv2.KeyPoint(*kp) for kp in kps_tuples]
return kps, des