[英]How to use OpenCV Stitcher class with Python?
I'm trying to use OpenCV Stitcher class with Python, with no luck.我正在尝试将 OpenCV Stitcher 类与 Python 一起使用,但没有成功。 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).我得到一个元组 (1, None)。
Following the C++ example, I tried to pass a numpy array as a second argument to stitch() with no luck.按照 C++ 示例,我尝试将一个 numpy 数组作为第二个参数传递给 stitch(),但没有成功。
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.结果元组的第一个值是错误代码,0 表示成功。 Here you got 1, which means, according to stitching.hpp
, that the process needs more images.这里你得到 1,这意味着,根据stitching.hpp
,该过程需要更多图像。
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. ERR_NEED_MORE_IMGS
通常表示您的图像中没有足够的关键点。
If you need more details about why the error occurs, you could switch to C++ and debug the process in details.如果您需要有关错误发生原因的更多详细信息,您可以切换到 C++ 并详细调试该过程。
Edit: providing working example编辑:提供工作示例
Same code as OP, just added result save and absolute paths.与 OP 相同的代码,只是添加了结果保存和绝对路径。
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酒吧.png
result.jpg结果.jpg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.