-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu_orb.cpp
More file actions
65 lines (52 loc) · 1.88 KB
/
cpu_orb.cpp
File metadata and controls
65 lines (52 loc) · 1.88 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
#include "diploma.hpp"
#include "track.hpp"
#include <opencv2/flann.hpp>
using namespace cv::cuda;
void cpu_orb(char *fileName) {
cv::VideoCapture cap(fileName);
if(!cap.isOpened()) {
std::cout << "[ERROR] bad video file" << std::endl;
return;
}
int nFrames = 50;
int nWinSize = 11;
auto pTracker = std::make_unique<Track::FeatureTracker>(nFrames, nWinSize);
cv::Ptr<cv::ORB> ORBDetector = cv::ORB::create(30);
cv::Mat frame, frameClone, grayed, descriptors, oldDescriptors;
std::vector<cv::KeyPoint> keypoints, oldKeypoints;
cv::FlannBasedMatcher matcher(new cv::flann::LshIndexParams(20, 10, 2));
std::cout << "[INFO] ORB on CPU" << std::endl;
while(cap.read(frame)) {
keypoints.clear();
frameClone = frame.clone();
cv::cvtColor(frame, grayed, cv::COLOR_RGB2GRAY);
uint64_t t0 = cv::getTickCount();
ORBDetector->detectAndCompute(frameClone, cv::noArray(), keypoints, descriptors);
uint64_t t1 = cv::getTickCount();
double timegap = (t1*1.0 - t0) / cv::getTickFrequency();
if(descriptors.empty()) {
std::cout << "[WARNING] no descriptors" << std::endl;
continue;
}
if(oldKeypoints.empty()) {
oldKeypoints = keypoints;
keypoints.clear();
oldDescriptors = descriptors.clone();
continue;
}
std::vector<std::vector<cv::DMatch>> vKnnMatches;
std::vector<cv::DMatch> dmMatches;
matcher.knnMatch(oldDescriptors, descriptors, vKnnMatches, 2 );
//-- Filter matches using the Lowe's ratio test
const float ratio_thresh = 0.7f;
for (size_t i = 0; i < vKnnMatches.size(); i++) {
if (vKnnMatches[i][0].distance < ratio_thresh * vKnnMatches[i][1].distance) {
dmMatches.push_back(vKnnMatches[i][0]);
}
}
std::cout << "elapsed time: " << timegap << "; featured found: " << keypoints.size() << "; features tracked: " << dmMatches.size() << std::endl;
oldKeypoints = keypoints;
oldDescriptors = descriptors.clone();
keypoints.clear();
}
}