1

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:

screen example

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?

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
  • I wish I saw this question sooner than two weeks later! I've answered this exact question before and wrote both Python and OpenCV functions to warp without cropping. The linked duplicate shows exactly how to do this yourself and links to GH repos for the tools. – alkasm Jul 27 '18 at 02:48

0 Answers0