2 #include "opencv2/core/core.hpp"
3 #include "opencv2/features2d/features2d.hpp"
4 #include "opencv2/highgui/highgui.hpp"
5 #include "opencv2/nonfree/nonfree.hpp"
12 printf("\nThis program demonstrates using features2d detector, descriptor extractor and simple matcher\n"
13 "Using the SURF desriptor:\n"
15 "Usage:\n matcher_simple <image1> <image2>\n");
18 int main(int argc, char** argv)
26 Mat img1 = imread(argv[1], IMREAD_GRAYSCALE);
27 Mat img2 = imread(argv[2], IMREAD_GRAYSCALE);
28 if(img1.empty() || img2.empty())
30 printf("Can't read one of the images\n");
34 // detecting keypoints
35 SurfFeatureDetector detector(400);
36 vector<KeyPoint> keypoints1, keypoints2;
37 detector.detect(img1, keypoints1);
38 detector.detect(img2, keypoints2);
40 // computing descriptors
41 SurfDescriptorExtractor extractor;
42 Mat descriptors1, descriptors2;
43 extractor.compute(img1, keypoints1, descriptors1);
44 extractor.compute(img2, keypoints2, descriptors2);
46 // matching descriptors
47 BFMatcher matcher(extractor.defaultNorm());
48 vector<DMatch> matches;
49 matcher.match(descriptors1, descriptors2, matches);
51 // drawing the results
52 namedWindow("matches", 1);
54 drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
55 imshow("matches", img_matches);