To create a panorama in python we can multiple images taken with overlapping fields of view and stich them into a wider panorama. In fact, this method will work for stitching images in any direction and does not have to be panoramas.
Firstly, Image stitching is the process of combining multiple images with overlapping fields of view to create a single larger image, also known as a panorama. The overlapping field of view should be roughly 40% of the total image, less will work if there are obvious features in the image.
Python’s OpenCV implementation uses an algorithm proposed by Matthew Brown and David G. Low to preform image stitching with minimal user intervention. At a high level the implimentation has 3 steps:
Image registration — the algrothim uses the Scale-invariant feature transform (SIFT) method on the input images to find features on the image. the features are then fed into the RANSAC (Random Sample Consensus) method to estimate the geometric transformation between the images.
Image warping — the geometric transformation estimates are then used to transform the input images and align them to their final position.
Blending — the algorithm then uses the multi band blending method to create a seamless transition between the images.
The python implementation is quiet straight forward. A Sticher object is created then the stitch function is called to create the output.
# Create a Stitcher object
# Use cv2.createStitcher() if you are using OpenCV 3
stitcher = cv2.Stitcher_create()
# Stitch the images together
# output status, result image
_ , result = stitcher.stitch(images)
# Return the result
As you can see the resulting image has some black boundaries around the edge, this occurs for a number of reasons including misalignment, perspective mish match, and Image distortion. with a slight crop we can remove this:
If you would like to get a copy of the code used in this article, it can be found here on Github.