OpenCV  5.0.0alpha
Open Source Computer Vision
Loading...
Searching...
No Matches
AKAZE local features matching

Prev Tutorial: Detection of planar objects
Next Tutorial: AKAZE and ORB planar tracking

Original author Fedor Morozov
Compatibility OpenCV >= 3.0

Introduction

In this tutorial we will learn how to use AKAZE [10] local features to detect and match keypoints on two images. We will find keypoints on a pair of images with given homography matrix, match them and count the number of inliers (i.e. matches that fit in the given homography).

You can find expanded version of this example here: https://github.com/pablofdezalc/test_kaze_akaze_opencv

Warning
You need the OpenCV contrib module xfeatures2d to be able to use the AKAZE features.

Data

We are going to use images 1 and 3 from Graffiti sequence of Oxford dataset.

Homography is given by a 3 by 3 matrix:

7.6285898e-01 -2.9922929e-01 2.2567123e+02
3.3443473e-01 1.0143901e+00 -7.6999973e+01
3.4663091e-04 -1.4364524e-05 1.0000000e+00

You can find the images (graf1.png, graf3.png) and homography (H1to3p.xml) in opencv/samples/data/.

Source Code

Explanation

  • Load images and homography

We are loading grayscale images here. Homography is stored in the xml created with FileStorage.

  • Detect keypoints and compute descriptors using AKAZE

We create AKAZE and detect and compute AKAZE keypoints and descriptors. Since we don't need the mask parameter, noArray() is used.

  • Use brute-force matcher to find 2-nn matches

We use Hamming distance, because AKAZE uses binary descriptor by default.

  • Use 2-nn matches and ratio criterion to find correct keypoint matches

If the closest match distance is significantly lower than the second closest one, then the match is correct (match is not ambiguous).

  • Check if our matches fit in the homography model

If the distance from first keypoint's projection to the second keypoint is less than threshold, then it fits the homography model.

We create a new set of matches for the inliers, because it is required by the drawing function.

  • Output results

Here we save the resulting image and print some statistics.

Results

Found matches

Depending on your OpenCV version, you should get results coherent with:

Keypoints 1: 2943
Keypoints 2: 3511
Matches: 447
Inliers: 308
Inlier Ratio: 0.689038