-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBFMatcher.cpp
More file actions
84 lines (48 loc) · 1.44 KB
/
BFMatcher.cpp
File metadata and controls
84 lines (48 loc) · 1.44 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
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <opencv2/opencv.hpp>
#include <iostream>
#include <cstdlib>
#include <cstdlib>
#include <random>
#include <vector>
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include <opencv2/xfeatures2d/nonfree.hpp>
#include <opencv2/xfeatures2d.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv){
cv::Mat img1;
cv::Mat img2;
img1 = cv::imread("t3.jpg");
// img2 = cv::imread("t4.jpg");
cv::namedWindow("img1");
cv::VideoCapture cap;
cap.open(0);
for(;;){
cap >> img2;
if(img2.empty()){
break;
}
std::vector<cv::KeyPoint> keypoints1, keypoints2;
cv::Ptr<cv::Feature2D> ptrFeature2D;
ptrFeature2D = cv::xfeatures2d::SURF::create(10000);
ptrFeature2D->detect(img1, keypoints1);
ptrFeature2D->detect(img2, keypoints2);
cv::Mat descriptor1;
cv::Mat descriptor2;
ptrFeature2D->compute(img1, keypoints1, descriptor1);
ptrFeature2D->compute(img2, keypoints2, descriptor2);
cv::BFMatcher matcher(cv::NORM_L2);
std::vector<cv::DMatch> matches;
matcher.match(descriptor1, descriptor2, matches);
cv::Mat matchImage;
cv::drawMatches(img1, keypoints1, img2, keypoints2, matches, matchImage, Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
matches.clear();
keypoints1.clear();
keypoints2.clear();
// cv::namedWindow("img2");
cv::imshow("img1",matchImage);
// cv::imshow("img2",result2);
cv::waitKey(1);
}
}