I am attempting to stitch 4 equally-sized images together, in the form of a grid.
I already have corresponding points between each of the 4 images (chosen manually due to the lack of complexity of the images). I am calculating the homography between each of the images using
h = cv2.findHomography(points1, points2, cv2.RANSAC, n)
and then transforming them using
img2Transformed = cv2.warpPerspective(img2, h, (YSHAPE, XSHAPE))
My problem lies in
(YSHAPE, XSHAPE)
I am not sure how to define this area. At first, I thought of setting it to (img1.shape[1] + img2.shape[1], img1.shape[0] + img2.shape[0])
and then setting the original coordinates of img2Transformed
to img1
using
img2Tranformed[:img1.shape[1], :img1.shape[0]] = img1
but then realized that the transformed image could have still been warped off the screen like this:
After obtaining a transformed image, how do I combine the two images without potentially cropping anything? And once I have done that, how do I make space for all 4 images?