1
+ #include < iostream>
2
+ #include < opencv2\opencv.hpp>
3
+ #include < opencv2\features2d.hpp>
4
+
5
+ using namespace cv ;
6
+ using namespace std ;
7
+
8
+ int main (int argc, char ** argv )
9
+ {
10
+ Mat imageA = imread (" data/images/box.png" , IMREAD_GRAYSCALE);
11
+ Mat imageB = imread (" data/images/box_in_scene.png" , IMREAD_GRAYSCALE);
12
+
13
+ if (imageA.empty () || imageB.empty ())
14
+ {
15
+ printf (" No image data." );
16
+ getchar ();
17
+
18
+ return -1 ;
19
+ }
20
+
21
+ Ptr<Feature2D> detect = BRISK::create ();
22
+
23
+ vector<KeyPoint> kpA, kpB;
24
+ Mat descA, descB;
25
+
26
+ detect->detectAndCompute (imageA, noArray (), kpA, descA);
27
+ detect->detectAndCompute (imageB, noArray (), kpB, descB);
28
+
29
+ vector<DMatch> matches;
30
+
31
+ Ptr<DescriptorMatcher> matcher = BFMatcher::create (NORM_HAMMING, true );
32
+ matcher->match (descA, descB, matches);
33
+
34
+ sort (matches.begin (), matches.end ());
35
+ matches.erase (matches.begin () + 35 , matches.end ());
36
+
37
+ Scalar color = Scalar::all (-1 );
38
+ int flags = DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS;
39
+
40
+ Mat result;
41
+ drawMatches (imageA, kpA, imageB, kpB, matches, result, color, color, vector<char >(), flags);
42
+
43
+ imshow (" OpenCV :: Match Keypoints" , result);
44
+ waitKey (0 );
45
+
46
+ return 0 ;
47
+ }
0 commit comments