forked from dorian3d/DBoW2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_vocab.cpp
95 lines (72 loc) · 2.49 KB
/
test_vocab.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
#include <iostream>
#include <vector>
// DBoW2
#include "DBoW2.h" // defines SuperPointVocabulary
// OpenCV
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/core/persistence.hpp>
using namespace DBoW2;
using namespace std;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void loadFeatures(vector<vector<cv::Mat > > &features, const string &feature_path);
void changeStructure(const cv::Mat &plain, vector<cv::Mat> &out);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// number of training images
const int NIMAGES = 5;
// ----------------------------------------------------------------------------
int main(int argc, char **argv)
{
if(argc != 3)
{
cerr << endl << "Usage: ./build_superpt_vocab path_to_superpoint_features "
"path_to_superpoint_vocabulary" << endl;
return 1;
}
// load the vocabulary from disk
SuperPointVocabulary voc(argv[2]);
// get features for a small number of images
vector<vector<cv::Mat > > features;
loadFeatures(features, argv[1]);
// score images to test vocab
cout << "Scoring image matches (0 low, 1 high): " << endl;
cout << "Images from FLIR ADAS videos frames: 1, 2, 15, 40, 4224" << endl;
BowVector v1, v2;
for(int i = 0; i < NIMAGES; i++)
{
voc.transform(features[i], v1);
for(int j = 0; j < NIMAGES; j++)
{
voc.transform(features[j], v2);
double score = voc.score(v1, v2);
cout << "Image " << i << " vs Image " << j << ": " << score << endl;
}
}
}
// ----------------------------------------------------------------------------
void loadFeatures(vector<vector<cv::Mat > > &features, const string &feature_path)
{
features.clear();
features.reserve(NIMAGES);
cout << "Importing SuperPoint features..." << endl;
for(int i = 1; i < NIMAGES + 1; ++i)
{
stringstream ss;
ss << feature_path << i << ".yaml";
cv::FileStorage pts_log(ss.str(), cv::FileStorage::READ);
cv::Mat descriptors;
pts_log["descriptors"] >> descriptors;
features.push_back(vector<cv::Mat >());
changeStructure(descriptors, features.back());
}
}
// ----------------------------------------------------------------------------
void changeStructure(const cv::Mat &plain, vector<cv::Mat> &out)
{
out.resize(plain.rows);
for(int i = 0; i < plain.rows; ++i)
{
out[i] = plain.row(i);
}
}