-
Notifications
You must be signed in to change notification settings - Fork 0
/
Surf.cpp
56 lines (46 loc) · 1.42 KB
/
Surf.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
/*
*
*
*/
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/xfeatures2d.hpp>
using namespace std;
using namespace cv;
using namespace cv::xfeatures2d;
int main(int argc, char* argv[]) {
if (argc < 3) {
cout << "Usage: file_1 file_2" << endl;
exit(0);
}
Mat img_1, img_2;
// Mat img_1c = imread("/scratch/CVDP/foo.tif");
// Mat img_2c = imread("/scratch/CVDP/foo.tif");
Mat img_1c = imread(argv[1]);
Mat img_2c = imread(argv[2]);
cvtColor(img_1c, img_1, CV_BGR2GRAY);
cvtColor(img_2c, img_2, CV_BGR2GRAY);
vector<KeyPoint> keypoints_1;
vector<KeyPoint> keypoints_2;
//SurfFeatureDetector surf(2.50e3);
Ptr<SURF> surf = SURF::create(2.50e2);
surf->detect(img_1, keypoints_1);
surf->detect(img_2, keypoints_2);
cv::Mat descriptors_1, descriptors_2;
//compute descriptors
surf->compute(img_1, keypoints_1, descriptors_1);
surf->compute(img_2, keypoints_2, descriptors_2);
//use brute force method to match vectors
BFMatcher* matcher = new BFMatcher(NORM_L1);
vector<DMatch>matches;
matcher->match(descriptors_1, descriptors_2, matches);
//draw results
Mat img_matches;
drawMatches(img_1c, keypoints_1, img_2c, keypoints_2, matches, img_matches);
imshow("surf_Matches", img_matches);
int keyCode;
do {
keyCode = waitKey(0);
cout << keyCode << endl;
} while (keyCode != 113); // "q"
}