-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.cpp
More file actions
70 lines (57 loc) · 2.74 KB
/
test.cpp
File metadata and controls
70 lines (57 loc) · 2.74 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
67
68
69
70
// https://stackoverflow.com/questions/43830849/opencv-use-flann-with-orb-descriptors-to-match-features
#include <iostream>
#include "DBoW3.h"
#include "c_cpp_utils/path.h"
// #include <math>
#include "opencv2/opencv.hpp"
using namespace DBoW3;
void myfun(cv::Mat& out) {
cv::Mat src = (cv::Mat_<double>(2, 3) << 1, 2, 3, 4, 5, 9);
out = cv::Mat(2, 3, CV_64F, src.data);
src.release();
}
int main(int argc, char** argv) {
std::string imagePath = "your_real_world_bev_images"; // download url, https://github.com/cuixing158/Visual-Based-Odometry-Estimation-cpp/releases/tag/v1.0.0
std::vector<std::string> imagePaths;
size_t numImgs = getFullNames(filesystem::path(imagePath), imagePaths, ".jpg");
// std::sort(imagePaths.begin(), imagePaths.end(),
// [](std::string p1, std::string p2) { return atoi(filesystem::path(p1).filenameNoExt().substr(6).c_str()) < atoi(filesystem::path(p2).filenameNoExt().substr(6).c_str()); });
std::sort(imagePaths.begin(), imagePaths.end(),
[](std::string p1, std::string p2) { return atoi(filesystem::path(p1).filenameNoExt().c_str()) < atoi(filesystem::path(p2).filenameNoExt().c_str()); });
std::vector<cv::KeyPoint> keypts;
cv::Mat feature;
std::vector<cv::Mat> features;
cv::Ptr<cv::ORB> orbDetector = cv::ORB::create();
for (size_t i = 0; i < 200; i++) {
cv::Mat srcImg = cv::imread(imagePaths[i], cv::IMREAD_COLOR);
cv::cvtColor(srcImg, srcImg, cv::COLOR_BGR2GRAY);
orbDetector->detectAndCompute(srcImg, cv::noArray(), keypts, feature);
features.push_back(feature);
}
std::string saveDataBaseYmlGz = "./database.yml.gz";
// branching factor and depth levels
const int k = 10;
const int L = 4;
const DBoW3::WeightingType weight = DBoW3::TF_IDF;
const DBoW3::ScoringType score = DBoW3::L1_NORM;
std::cout << "From features,Create vocabulary,please wait ..." << std::endl;
DBoW3::Vocabulary voc(k, L, weight, score);
voc.create(features);
Database db;
db.setVocabulary(voc, false, 0); // false = do not use direct index
// (so ignore the last param)
// The direct index is useful if we want to retrieve the features that
// belong to some vocabulary node.
// db creates a copy of the vocabulary, we may get rid of "voc" now
// add images to the database
for (size_t i = 0; i < features.size(); i++)
db.add(features[i]);
std::cout << "add features per image done!" << std::endl;
std::string databaseFile = saveDataBaseYmlGz;
std::cout << "Vocabulary information: " << std::endl
<< voc << std::endl
<< "have saved this path:" << databaseFile << std::endl;
db.save(databaseFile);
db.load(databaseFile);
return 0;
}