There has been a lot of work in image stitching over the years, but we will take a look at the algorithm OpenCV implements internally. Most of it was proposed by Michael Brown and David Lowe. Image stitching is done in the following steps:
Find suitable features and match them reliably across the set of images to obtain the relative positioning.
Develop the geometry to choose reliable features that are invariant to rotation, scale, and illumination.
Match images using the RANSAC algorithm and a probabilistic model for verification.
Align the matched images.
Render the results to obtain a panoramic image. We use automatic straightening, gain compensation, and multi-band blending to achieve a seamlessly stitched panoramic image, as shown here: