John Doenut
John Doenut

Reputation: 195

In openCV warpPerspective, how do I transform the left image and stitch it to the image on the right?

I'm trying to do an image stitch using OpenCV by doing SIFT->KNN->warpPerspective. There are whole lot of resource on how to warp the image on the right to be stitched on to the destination on the left. I've tried calculating the homography matrix for warping left image to be stitched to the right and that seems to work. Problem is, I can't stitch the image together with cv2.warpPerspective since it seems to put the image in where it should be if the right side image is warped.

My code is basically:

result = cv2.warpPerspective(left, H, (left.shape[1] + right.shape[1], left.shape[0])
result[0:right.shape[0], result.shape[1]-right[1]:] = right

But this creates image offset shifted to the right. How could I stitch the images correctly?

Upvotes: 0

Views: 3430

Answers (2)

ksasi
ksasi

Reputation: 71

Yes, it appears there are good number of resources to warp the image on the right to be stitched on to the destination on the left. However if we want to do the opposite of this i.e. transform the left image and stitch it to the image on the right, we can simply flip both the images then warp the image on the right to be stitched on to the destination on the left and then can flip the result back. This will be then equivalent to transform the left image and stitch it to the image on the right.

Upvotes: 1

elpida_k
elpida_k

Reputation: 19

First you should resize the images and place them in a bigger image each with outer_x= image_x*5 and outer_y= image_y*3

outer_x= image_x*5
outer_y= image_y*3
result = cv.warpPerspective(left_image, H, (outer_x, outer_y))
result[:, x_img * 2 : x_img*3] = right_image[j][:, x_img * 2 : x_img*3]

Upvotes: 1

Related Questions