-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbow_eval.cpp
More file actions
66 lines (50 loc) · 1.85 KB
/
Copy pathdbow_eval.cpp
File metadata and controls
66 lines (50 loc) · 1.85 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
#include <iostream>
#include <string>
#include <DBoW3/DBoW3.h>
#include "util/multi_descriptor.h"
int main(int argc, char** argv) {
if (argc != 2) {
std::cerr << "second arg is the path to vocabulary file" << std::endl;
return 1;
}
const std::string kFilePrefix = std::string(argv[1]) + "/";
const std::string kDatabasePath = kFilePrefix + "vocabulary.bin";
DBoW3::Vocabulary vocab(kDatabasePath);
if (vocab.empty()) {
std::cerr << "vocab is empty" << std::endl;
return 1;
}
std::vector<cv::Mat> eval_images;
constexpr int kImageStart = 1;
constexpr int kImageEnd = 10;
util::multi_imread(eval_images, kFilePrefix, kImageStart, kImageEnd);
std::vector<cv::Mat> orb_descriptors;
util::multi_descriptor_detect(orb_descriptors, eval_images);
std::cout << "performing image to image comparison" << std::endl;
for (size_t i = 0; i < orb_descriptors.size(); ++i) {
DBoW3::BowVector v1;
vocab.transform(orb_descriptors[i], v1);
for (size_t j = i; j < orb_descriptors.size(); ++j) {
DBoW3::BowVector v2;
vocab.transform(orb_descriptors[j], v2);
const double similarity_score = vocab.score(v1, v2);
std::cout << "images " << i << ", " << j << ": " << similarity_score
<< std::endl;
}
}
std::cout << "performing image to database comparison" << std::endl;
constexpr bool kUseDirectIndex = false;
constexpr int kDirectIndexLevels = 0;
DBoW3::Database db(vocab, kUseDirectIndex, kDirectIndexLevels);
for (const cv::Mat& descriptor : orb_descriptors) {
db.add(descriptor);
}
std::cout << db << std::endl;
constexpr int kMaxQueryReturn = 4;
for (size_t i = 0; i < orb_descriptors.size(); ++i) {
DBoW3::QueryResults res;
db.query(orb_descriptors[i], res, kMaxQueryReturn);
std::cout << "query image " << i << " returns " << res << std::endl;
}
return 0;
}