'OpenCV Stitcher class not working in Python, always returns ERR_NEED_MORE_IMGS

I'm trying to use the OpenCV Stitcher class for putting two images together. I ran the simple example provided in the answer to this question with the same koala images, but it returns (1, None) every time. I've tried this on opencv-python version 3.4, 4.2, and 4.4, and all have the same result.

I've tried replacing the stitcher initializer with something else, (cv2.Stitcher.create, cv2.Stitcher_create, cv2.createStitcher), but nothing seems to work. If it helps, I'm on Mac Catalina, using Python 3.7. Thanks!



Solution 1:[1]

Try changing the default pano confidence threshold using setPanoConfidenceThresh(). By default it's 1.0, and apparently it results in the stitcher thinking that it has failed.

Here is the full example that works for me. I used that pair of koala images as well, and I am on opencv 4.2.0:

stitcher = cv2.Stitcher.create(cv2.Stitcher_PANORAMA)
stitcher.setPanoConfidenceThresh(0.0) # might be too aggressive for real examples
foo = cv2.imread("/path/to/image1.jpg")
bar = cv2.imread("/path/to/image2.jpg")
status, result = stitcher.stitch((foo,bar))
assert status == 0 # Verify returned status is 'success'
cv2.imshow("result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()

I think in this particular case cv2.Stitcher_SCANS is a better mode (transformation between images is just a translation), but either SCANS or PANORAMA works.

Solution 2:[2]

Try rescaling the images to 0.6 and 0.6 , by using the resize. For some reason I got the result only at those values.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vasiliykarasev
Solution 2 Ashper Sega