17

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.

1
  • This is a very interesting problem. I do not find any python documentation for this function, though it is there. Commented Apr 11, 2016 at 18:11

1 Answer 1

23
+50

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

foo.png

bar.png

bar.png

result.jpg

result.jpg

Sign up to request clarification or add additional context in comments.

9 Comments

Gwen, thanks for taking interest in that problem. We want to have a python solution, can you give an example in python with images you provide?
Does not work for me yet, have demonstrated my problems with separate answer above. Can you help?
I can't comment your answer (not enough reputation...). There is a bug in OpenCV 3.0+. It remains quite unclear but seems to be linked to OpenCL integration (see this bug report for example). You need to rebuild OpenCV without OpenCL support, and maybe comment line 163 of cv2.cpp (//CV_Error(Error::StsAssert, "The data should normally be NULL!");)
@tfv and I'm using python 2.7 and OpenCV 3.1.0 too.
That's a Koala Bear! Also the bug which causes error on line 163, seems to be resolved in OpenCV 3.3.0. Thanks for the well written answer.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.