How to do it...

The following are the steps that you will follow (you will have to implement a few functions) to implement image stitching/mosaicing:

  1. First, implement the compute_homography() function, which computes the homography matrix, h, from two given input images:
def compute_homography(image1, image2, bff_match=False):
  1. Similar to the previous recipe, first compute keypoints/descriptors (this time use SIFT):
 sift = cv2.xfeatures2d.SIFT_create(edgeThreshold=10, sigma=1.5, \                                     contrastThreshold=0.08) kp1, des1 = sift.detectAndCompute(image1, None) kp2, des2 = sift.detectAndCompute(image2, None)
  1. Match the descriptors using brute-force knnMatch() and then select the good matches using Lowe's ratio test:
 bf = cv2.BFMatcher() # Brute ...

Get Python Image Processing 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.