Finding reliable matches - cross-check and ratio test
In this recipe, you will learn how filter keypoint matches using cross-check and ratio tests. These techniques are useful for filtering bad matches and improving the overall quality of established correspondences.
Getting ready
Before you proceed with this recipe, you need to install the OpenCV version 3.3 (or greater) Python API package.
How to do it...
You need to complete the following steps:
- Import the necessary modules:
import cv2 import matplotlib.pyplot as plt
- Load the test images:
img0 = cv2.imread('../data/Lena.png', cv2.IMREAD_GRAYSCALE) img1 = cv2.imread('../data/Lena_rotated.png', cv2.IMREAD_GRAYSCALE)
- Create the detector, detect keypoints, and computer descriptors:
detector = cv2.ORB_create(100) kps0, fea0 = detector.detectAndCompute(img0, None) kps1, fea1 = detector.detectAndCompute(img1, None)
- Create the k-nearest neighbor descriptor matcher with k=2, and find matches from left to right and vice versa:
matcher = cv2.BFMatcher_create...