opencv2 stitching images together failed

108 Views Asked by At

I want to stitch together a bunch of images with OpenCV2 with python. Since it is very time consuming to stitch together 30+ images I modified my code to just stitch together 2 images and after that stitch together the next image with the previous stitched image.

But when running the code even at the first stitch it will run into an error with the status code 1 and I dont know why. I even tested it with only 2 images in the folder but with the same result so it seems like I made an error somewhere in the code.

Full code:

from imutils import paths
import numpy as np
import imutils
import cv2


print("[INFO] loading images...")
imagePaths = sorted(list(paths.list_images("./images/")))
images = []


for imagePath in imagePaths:
    image = cv2.imread(imagePath)
    images.append(image)
i = 0
currentImage = None
while len(images) > i + 1: #loop through all images. Use i+1 because we used i+1 to get the next image down below. If we get to the last image there is no next image
    imagesToCombine = []
    if i == 0:
        imagesToCombine.append(images[i]) #Use first image at the first run
    else:
        imagesToCombine.append(currentImage) #Use the last stiched image
    imagesToCombine.append(images[i + 1])

    print("[INFO] stitching images...")
    stitcher = cv2.createStitcher() if imutils.is_cv3() else cv2.Stitcher_create()
    (status, stitched) = stitcher.stitch(imagesToCombine)

    if status == 0:
            currentImage = stitched
            print("Done" + str(i))
            i += 1
    else:
            print("[INFO] image stitching failed ({})".format(status))
            break
if currentImage is not None:
    cv2.imwrite("./stiched.png", currentImage)
print("Done")

Console output:

[INFO] loading images...
[INFO] stitching images...
[INFO] image stitching failed (1)
Done

Edit:

After I wanted to create another set of example images I saw that with those images it was working! So somehow the images I actually want to combine doesn't work somehow even when they have a good portion of overlap.

Those images doesn't work: https://i.stack.imgur.com/pIjrs.jpg

But those images do work: https://i.stack.imgur.com/0zG9U.jpg

Any Idea why the other images don't work?

0

There are 0 best solutions below