1 AKAZE local features matching {#tutorial_akaze_matching}
2 =============================
4 @prev_tutorial{tutorial_detection_of_planar_objects}
5 @next_tutorial{tutorial_akaze_tracking}
10 In this tutorial we will learn how to use AKAZE @cite ANB13 local features to detect and match keypoints on
12 We will find keypoints on a pair of images with given homography matrix, match them and count the
13 number of inliers (i.e. matches that fit in the given homography).
15 You can find expanded version of this example here:
16 <https://github.com/pablofdezalc/test_kaze_akaze_opencv>
21 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).
25 Homography is given by a 3 by 3 matrix:
27 7.6285898e-01 -2.9922929e-01 2.2567123e+02
28 3.3443473e-01 1.0143901e+00 -7.6999973e+01
29 3.4663091e-04 -1.4364524e-05 1.0000000e+00
31 You can find the images (*graf1.png*, *graf3.png*) and homography (*H1to3p.xml*) in
32 *opencv/samples/data/*.
37 - **Downloadable code**: Click
38 [here](https://raw.githubusercontent.com/opencv/opencv/3.4/samples/cpp/tutorial_code/features2D/AKAZE_match.cpp)
41 @include samples/cpp/tutorial_code/features2D/AKAZE_match.cpp
45 - **Downloadable code**: Click
46 [here](https://raw.githubusercontent.com/opencv/opencv/3.4/samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java)
49 @include samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java
53 - **Downloadable code**: Click
54 [here](https://raw.githubusercontent.com/opencv/opencv/3.4/samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py)
57 @include samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py
62 - **Load images and homography**
65 @snippet samples/cpp/tutorial_code/features2D/AKAZE_match.cpp load
69 @snippet samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java load
73 @snippet samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py load
76 We are loading grayscale images here. Homography is stored in the xml created with FileStorage.
78 - **Detect keypoints and compute descriptors using AKAZE**
81 @snippet samples/cpp/tutorial_code/features2D/AKAZE_match.cpp AKAZE
85 @snippet samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java AKAZE
89 @snippet samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py AKAZE
92 We create AKAZE and detect and compute AKAZE keypoints and descriptors. Since we don't need the *mask*
93 parameter, *noArray()* is used.
95 - **Use brute-force matcher to find 2-nn matches**
98 @snippet samples/cpp/tutorial_code/features2D/AKAZE_match.cpp 2-nn matching
102 @snippet samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java 2-nn matching
106 @snippet samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py 2-nn matching
109 We use Hamming distance, because AKAZE uses binary descriptor by default.
111 - **Use 2-nn matches and ratio criterion to find correct keypoint matches**
113 @snippet samples/cpp/tutorial_code/features2D/AKAZE_match.cpp ratio test filtering
117 @snippet samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java ratio test filtering
121 @snippet samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py ratio test filtering
124 If the closest match distance is significantly lower than the second closest one, then the match is correct (match is not ambiguous).
126 - **Check if our matches fit in the homography model**
129 @snippet samples/cpp/tutorial_code/features2D/AKAZE_match.cpp homography check
133 @snippet samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java homography check
137 @snippet samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py homography check
140 If the distance from first keypoint's projection to the second keypoint is less than threshold,
141 then it fits the homography model.
143 We create a new set of matches for the inliers, because it is required by the drawing function.
148 @snippet samples/cpp/tutorial_code/features2D/AKAZE_match.cpp draw final matches
152 @snippet samples/java/tutorial_code/features2D/akaze_matching/AKAZEMatchDemo.java draw final matches
156 @snippet samples/python/tutorial_code/features2D/akaze_matching/AKAZE_match.py draw final matches
159 Here we save the resulting image and print some statistics.
168 Depending on your OpenCV version, you should get results coherent with:
175 Inlier Ratio: 0.689038