How to do it...

You need to complete the following steps:

  1. Import the necessary modules:
import cv2import matplotlib.pyplot as plt
  1. Load the test images:
img0 = cv2.imread('../data/Lena.png', cv2.IMREAD_GRAYSCALE)img1 = cv2.imread('../data/Lena_rotated.png', cv2.IMREAD_GRAYSCALE)
  1. 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)
  1. Create the k-nearest neighbor descriptor matcher with k=2, and find matches from left to right and vice versa:
matcher = cv2.BFMatcher_create(cv2.NORM_HAMMING, False)matches01 = matcher.knnMatch(fea0, fea1, k=2)matches10 = matcher.knnMatch(fea1, fea0, k=2)
  1. Create ...

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.