2

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!

Andy K
  • 151
  • 1
  • 9

2 Answers2

2

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.

vasiliykarasev
  • 851
  • 4
  • 10
  • 2
    Almost worked, got it to output something by using `Stitcher_SCANS` and setting pano confidence threshold to 0.0. However, it always outputs one one or the other image, and not any overlap. Is there anything else I can try? – Andy K Nov 15 '20 at 01:25
0

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.