rama
rama

Reputation: 1

How to stitch these two images with some Python code using OpenCV?

I have two images

Image 1:

Image-1

Image 2:

Image-2

I tried various approaches but I got some errors. I also tried this approach. So, can we stitch these two images? If so, how can I do this in Python3?

Upvotes: 0

Views: 2294

Answers (1)

Kardi Teknomo
Kardi Teknomo

Reputation: 1460

What would be your error? I tested using your images and it indeed produces error because OpenCV Stitcher cannot find the overlapping features between the two images. You can try to other images with at least 25% overlapping between the two images and use the simpler code for image stitching below.

import cv2

img1 = cv2.imread("image1.jpg")
img2 = cv2.imread("image2.jpg")
tupleImages=(img1,img2)
stitcher = cv2.createStitcher(True)
result = stitcher.stitch(tupleImages)
cv2.imshow('result',result[1]) 
k = cv2.waitKey(0) & 0xff # press ESC to exit
if k == 27:
    cv2.destroyAllWindows()

Try using the images below house2enter image description here and the result would beenter image description here

Upvotes: 2

Related Questions