I'm trying to use OpenCV Stitcher class with Python, with no luck. My code is:
import cv2
stitcher = cv2.createStitcher(False)
foo = cv2.imread("foo.png")
bar = cv2.imread("bar.png")
result = stitcher.stitch((foo,bar))
I get a tuple with (1, None).
Following the C++ example, I tried to pass a numpy array as a second argument to stitch() with no luck.
You're using it right, be the process failed for some reason.
The first value of the result tuple is an error code, with 0 indicating success. Here you got 1, which means, according to stitching.hpp
, that the process needs more images.
enum Status
{
OK = 0,
ERR_NEED_MORE_IMGS = 1,
ERR_HOMOGRAPHY_EST_FAIL = 2,
ERR_CAMERA_PARAMS_ADJUST_FAIL = 3
};
ERR_NEED_MORE_IMGS
usually indicates that you don't have enough keypoints in your images.
If you need more details about why the error occurs, you could switch to C++ and debug the process in details.
Edit : providing working example
Same code as OP, just added result save and absolute paths.
import cv2
stitcher = cv2.createStitcher(False)
foo = cv2.imread("D:/foo.png")
bar = cv2.imread("D:/bar.png")
result = stitcher.stitch((foo,bar))
cv2.imwrite("D:/result.jpg", result[1])
with these images: (I hope you love koalas)
foo.png
bar.png
result.jpg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With