-
Notifications
You must be signed in to change notification settings - Fork 32
/
feature_based_matching_dh.cpp
127 lines (106 loc) · 4.6 KB
/
feature_based_matching_dh.cpp
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
/** vpr_relocalization: a library for visual place recognition in changing
** environments with efficient relocalization step.
** Copyright (c) 2017 O. Vysotska, C. Stachniss, University of Bonn
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
** SOFTWARE.
**/
#include <QApplication>
#include <memory>
#include <thread>
#include "database/idatabase.h"
#include "database/online_database.h"
#include "online_localizer/ilocvisualizer.h"
#include "online_localizer/online_localizer.h"
#include "successor_manager/successor_manager.h"
#include "relocalizers/dimensions_hashing.h"
#include "tools/config_parser/config_parser.h"
#include "visualizer/match_viewer.h"
#include "visualizer/visualizer.h"
using std::make_shared;
void localize(OnlineLocalizer *loc) { loc->run(); }
int main(int argc, char *argv[]) {
printf("===== Online place recognition using DH ====\n");
if (argc < 2) {
printf("[ERROR] Not enough input parameters.\n");
printf("Proper usage: ./feature_based_matching_dh config_file.yaml\n");
exit(0);
}
std::string config_file = argv[1];
ConfigParser parser;
parser.parseYaml(config_file);
parser.print();
OnlineDatabase online_database;
online_database.setRefFeaturesFolder(parser.path2ref);
online_database.setQuFeaturesFolder(parser.path2qu);
online_database.setBufferSize(parser.bufferSize);
online_database.setFeatureType(
FeatureFactory::FeatureType::Cnn_Feature);
//[VGG] uncomment this to use Vgg_features
// FeatureFactory::FeatureType::Vgg_Feature);
if (!online_database.isSet()) {
printf("[ERROR] database is not set completely\n");
return false;
}
auto onlineDatabasePtr = make_shared<OnlineDatabase>(online_database);
// initialize Relocalizer
auto relocalizerPtr = DimensionsHashing::Ptr(new DimensionsHashing);
relocalizerPtr->loadIndex(parser.hashTable);
relocalizerPtr->weightIndex(onlineDatabasePtr->refSize());
relocalizerPtr->setDatabase(onlineDatabasePtr);
// initialize SuccessorManager
auto successorManagerPtr = make_shared<SuccessorManager>(SuccessorManager());
successorManagerPtr->setFanOut(parser.fanOut);
successorManagerPtr->setDatabase(onlineDatabasePtr);
successorManagerPtr->setSimilarPlaces(parser.simPlaces);
successorManagerPtr->setRelocalizer(relocalizerPtr);
QApplication app(argc, argv);
Visualizer *visualizer = new Visualizer();
visualizer->setWindowTitle(
QApplication::translate("toplevel", "Olga's awesome viewer"));
MatchViewer *matchViewer = new MatchViewer();
matchViewer->setQueryImages(parser.path2quImg);
matchViewer->setRefImages(parser.path2refImg);
matchViewer->setImageExtension(parser.imgExt);
matchViewer->setDatabase(onlineDatabasePtr);
LocalizationViewer *locViewer = new LocalizationViewer();
locViewer->setDatabase(onlineDatabasePtr);
if (!visualizer->setMatchViewer(matchViewer)) {
printf("[ERROR] MatchViewer was not set\n");
}
if (!visualizer->setLocalizationViewer(locViewer)) {
printf("[ERROR] LocalizationViewer was not set\n");
}
printf("[INFO] Visualizer was initialized\n");
auto visPtr = iLocVisualizer::Ptr(visualizer);
OnlineLocalizer localizer;
localizer.setQuerySize(parser.querySize);
localizer.setSuccessorManager(successorManagerPtr);
localizer.setExpansionRate(parser.expansionRate); // expand everything
localizer.setNonMatchingCost(parser.nonMatchCost);
if (visualizer->isReady()) {
localizer.setVisualizer(visPtr);
}
std::thread process(localize, &localizer);
app.exec();
printf("%s\n", "Visualizer closed.");
std::string pathFile = "matched_path.txt";
localizer.printPath(pathFile);
process.join();
return 0;
}