-
Notifications
You must be signed in to change notification settings - Fork 393
/
Copy pathloop_detector_vocabulary.py
133 lines (109 loc) · 5.79 KB
/
loop_detector_vocabulary.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"""
* 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 time
import math
import numpy as np
import platform
from utils_sys import getchar, Printer
from config_parameters import Parameters
from utils_files import gdrive_download_lambda
from feature_types import FeatureDetectorTypes, FeatureDescriptorTypes
from utils_serialization import Serializable, register_class
kVerbose = True
kScriptPath = os.path.realpath(__file__)
kScriptFolder = os.path.dirname(kScriptPath)
kRootFolder = kScriptFolder + '/..'
kDataFolder = kRootFolder + '/data'
if Parameters.kLoopClosingDebugAndPrintToFile:
from loop_detector_base import print
# NOTE: At present, under mac, boost serialization is very slow, we use txt files instead.
def dbow2_orb_vocabulary_factory(*args, **kwargs):
use_text_vocabulary = platform.system() == 'Darwin'
if use_text_vocabulary:
return DBowOrbVocabularyDataTxt(*args, **kwargs)
else:
return DBow2OrbVocabularyData(*args, **kwargs)
# NOTE: at present, under mac, boost serialization is very slow, we use txt files instead.
def dbow3_orb_vocabulary_factory(*args, **kwargs):
use_text_vocabulary = platform.system() == 'Darwin'
if use_text_vocabulary:
return DBowOrbVocabularyDataTxt(*args, **kwargs)
else:
return DBow3OrbVocabularyData(*args, **kwargs)
@register_class
class VocabularyData(Serializable):
def __init__(self, vocab_file_path=None, descriptor_type=None, descriptor_dimension=None, url_vocabulary=None, url_type=None):
self.vocab_file_path = vocab_file_path
self.descriptor_type = descriptor_type
self.descriptor_dimension=descriptor_dimension
self.url_vocabulary = url_vocabulary
self.url_type = url_type
def check_download(self):
if self.url_vocabulary is not None and not os.path.exists(self.vocab_file_path):
if self.url_type == 'gdrive':
gdrive_url = self.url_vocabulary
Printer.blue(f'VocabularyData: downloading vocabulary {self.descriptor_type.name} from: {gdrive_url}')
try:
gdrive_download_lambda(url=gdrive_url, path=self.vocab_file_path)
except Exception as e:
Printer.red(f'VocabularyData: cannot download vocabulary from {gdrive_url}')
raise e
if self.vocab_file_path is not None and not os.path.exists(self.vocab_file_path):
Printer.red(f'VocabularyData: cannot find vocabulary file: {self.vocab_file_path}')
raise FileNotFoundError
# NOTE: Under mac, loading the DBOW2 vocabulary is very slow (both from text and from boost archive).
@register_class
class DBowOrbVocabularyDataTxt(VocabularyData):
kOrbVocabFile = kDataFolder + '/ORBvoc.txt'
def __init__(self, vocab_file_path=kOrbVocabFile,
descriptor_type=FeatureDescriptorTypes.ORB2,
descriptor_dimension=32,
url_vocabulary='https://drive.google.com/uc?id=1-4qDFENJvswRd1c-8koqt3_5u1jMR4aF',
url_type='gdrive'): # download it from gdrive
super().__init__(vocab_file_path, descriptor_type, descriptor_dimension, url_vocabulary, url_type)
# NOTE: Under mac, loading the DBOW2 vocabulary is very slow (both from text and from boost archive).
@register_class
class DBow2OrbVocabularyData(VocabularyData):
kOrbVocabFile = kDataFolder + '/ORBvoc.dbow2'
def __init__(self, vocab_file_path=kOrbVocabFile,
descriptor_type=FeatureDescriptorTypes.ORB2,
descriptor_dimension=32,
url_vocabulary='https://drive.google.com/uc?id=1pvBERLLSUV4IcaInNJMURTb8p-r9-5Xf',
url_type='gdrive'): # download it from gdrive
super().__init__(vocab_file_path, descriptor_type, descriptor_dimension, url_vocabulary, url_type)
# NOTE: Under mac, loading the DBOW2 vocabulary is very slow (both from text and from boost archive).
@register_class
class DBow3OrbVocabularyData(VocabularyData):
kOrbVocabFile = kDataFolder + '/ORBvoc.dbow3'
def __init__(self, vocab_file_path=kOrbVocabFile,
descriptor_type=FeatureDescriptorTypes.ORB2,
descriptor_dimension=32,
url_vocabulary='https://drive.google.com/uc?id=13xmRtop_ow3aPtv3qCT5beG19_mlogqI',
url_type='gdrive'): # download it from gdrive
super().__init__(vocab_file_path, descriptor_type, descriptor_dimension, url_vocabulary, url_type)
@register_class
class VladOrbVocabularyData(VocabularyData):
kVladVocabFile = kDataFolder + '/VLADvoc_orb.txt'
def __init__(self, vocab_file_path=kVladVocabFile,
descriptor_type=FeatureDescriptorTypes.ORB2,
descriptor_dimension=32,
url_vocabulary='https://drive.google.com/file/d/1u6AJEa2aZg7u5aS6vFX2qXiKKePQ_6t2',
url_type='gdrive'): # download it from gdrive
super().__init__(vocab_file_path, descriptor_type, descriptor_dimension, url_vocabulary, url_type)