How to use OpenCV Stitcher class with Python?

I am trying to use the 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, No).

Following the C ++ example, I tried passing the numpy array as the second argument to stitch () without any luck.

+5
source share
1 answer

You use it correctly, for some reason the process was unsuccessful.

The first value of the result tuple is the error code, with 0 indicating success. Here you get 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 there are not enough key points in your images.

If you need more information about the cause of the error, you can switch to C ++ and debug the process in detail.


Edit: providing a working example

The same code as the OP just added result persistence 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: (hope you like pandas)

foo.png

foo.png

bar.png

bar.png

result.jpg

result.jpg

+8
source

Source: https://habr.com/ru/post/1238668/


All Articles