1 AKAZE local features matching {#tutorial_akaze_matching}
2 =============================
7 In this tutorial we will learn how to use AKAZE @cite ANB13 local features to detect and match keypoints on
9 We will find keypoints on a pair of images with given homography matrix, match them and count the
10 number of inliers (i.e. matches that fit in the given homography).
12 You can find expanded version of this example here:
13 <https://github.com/pablofdezalc/test_kaze_akaze_opencv>
18 We are going to use images 1 and 3 from *Graffiti* sequence of [Oxford dataset](http://www.robots.ox.ac.uk/~vgg/data/data-aff.html).
22 Homography is given by a 3 by 3 matrix:
24 7.6285898e-01 -2.9922929e-01 2.2567123e+02
25 3.3443473e-01 1.0143901e+00 -7.6999973e+01
26 3.4663091e-04 -1.4364524e-05 1.0000000e+00
28 You can find the images (*graf1.png*, *graf3.png*) and homography (*H1to3p.xml*) in
29 *opencv/samples/data/*.
34 - **Downloadable code**: Click
35 [here](https://raw.githubusercontent.com/opencv/opencv/3.4/samples/cpp/tutorial_code/features2D/AKAZE_match.cpp)
38 @include samples/cpp/tutorial_code/features2D/AKAZE_match.cpp
42 - **Downloadable code**: Click
43 [here](https://raw.githubusercontent.com/opencv/opencv/3.4/samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java)
46 @include samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java
50 - **Downloadable code**: Click
51 [here](https://raw.githubusercontent.com/opencv/opencv/3.4/samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py)
54 @include samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py
59 - **Load images and homography**
62 @snippet samples/cpp/tutorial_code/features2D/AKAZE_match.cpp load
66 @snippet samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java load
70 @snippet samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py load
73 We are loading grayscale images here. Homography is stored in the xml created with FileStorage.
75 - **Detect keypoints and compute descriptors using AKAZE**
78 @snippet samples/cpp/tutorial_code/features2D/AKAZE_match.cpp AKAZE
82 @snippet samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java AKAZE
86 @snippet samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py AKAZE
89 We create AKAZE and detect and compute AKAZE keypoints and descriptors. Since we don't need the *mask*
90 parameter, *noArray()* is used.
92 - **Use brute-force matcher to find 2-nn matches**
95 @snippet samples/cpp/tutorial_code/features2D/AKAZE_match.cpp 2-nn matching
99 @snippet samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java 2-nn matching
103 @snippet samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py 2-nn matching
106 We use Hamming distance, because AKAZE uses binary descriptor by default.
108 - **Use 2-nn matches and ratio criterion to find correct keypoint matches**
110 @snippet samples/cpp/tutorial_code/features2D/AKAZE_match.cpp ratio test filtering
114 @snippet samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java ratio test filtering
118 @snippet samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py ratio test filtering
121 If the closest match distance is significantly lower than the second closest one, then the match is correct (match is not ambiguous).
123 - **Check if our matches fit in the homography model**
126 @snippet samples/cpp/tutorial_code/features2D/AKAZE_match.cpp homography check
130 @snippet samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java homography check
134 @snippet samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py homography check
137 If the distance from first keypoint's projection to the second keypoint is less than threshold,
138 then it fits the homography model.
140 We create a new set of matches for the inliers, because it is required by the drawing function.
145 @snippet samples/cpp/tutorial_code/features2D/AKAZE_match.cpp draw final matches
149 @snippet samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java draw final matches
153 @snippet samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py draw final matches
156 Here we save the resulting image and print some statistics.
165 Depending on your OpenCV version, you should get results coherent with:
172 Inlier Ratio: 0.689038