forked from luigifreda/pyslam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature_l2net_keras.py
81 lines (61 loc) · 2.7 KB
/
feature_l2net_keras.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
"""
* 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 config
config.cfg.set_lib('l2net_keras')
import os
import sys
import time
import cv2
import numpy as np
from L2_Net import L2Net
from utils import Printer
from utils_features import extract_patches_tensor, extract_patches_array, extract_patches_array_cpp
kVerbose = True
# interface for pySLAM
class L2NetKerasFeature2D:
def __init__(self, do_tf_logging=False):
print('Using L2NetKerasFeature2D')
# One of "L2Net-HP", "L2Net-HP+", "L2Net-LIB", "L2Net-LIB+", "L2Net-ND", "L2Net-ND+", "L2Net-YOS", "L2Net-YOS+",
self.net_name = 'L2Net-HP+'
# mag_factor is how many times the original keypoint scale
# is enlarged to generate a patch from a keypoint
self.mag_factor = 3
# inference batch size
self.batch_size = 512
self.process_all = True # process all the patches at once
print('==> Loading pre-trained network.')
self.l2net = L2Net(self.net_name, do_tf_logging=do_tf_logging)
print('==> Successfully loaded pre-trained network.')
def compute(self, frame, kps, mask=None): #mask is a fake input
#print('kps: ', kps)
if len(kps)>0:
if False:
# use python code
patches = extract_patches_array(frame, kps, patch_size=32, mag_factor=self.mag_factor)
else:
# use faster cpp code
patches = extract_patches_array_cpp(frame, kps, patch_size=32, mag_factor=self.mag_factor)
patches = np.asarray(patches)
patches = np.expand_dims(patches, -1)
self.des = self.l2net.calc_descriptors(patches)
else:
self.des = []
if kVerbose:
print('descriptor: L2NET, #features: ', len(kps), ', frame res: ', frame.shape[0:2])
return kps, self.des