问题描述
我正在尝试将OpenCV Stitcher类与Python配合使用,但没有运气.我的代码是:
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))
我得到一个带有(1,None)的元组.
I get a tuple with (1, None).
在C ++示例之后,我尝试将numpy数组作为第二个参数传递给itchle(),但是没有运气.
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.
结果元组的第一个值是错误代码,0表示成功.在这里,您得到1,根据stitching.hpp
,这意味着该过程需要更多图像.
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
通常表示图像中没有足够的关键点.
ERR_NEED_MORE_IMGS
usually indicates that you don't have enough keypoints in your images.
如果您需要更多有关错误发生原因的详细信息,可以切换到C ++并详细调试过程.
If you need more details about why the error occurs, you could switch to C++ and debug the process in details.
提供工作示例
与OP相同的代码,只是添加了结果保存和绝对路径.
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 pandas)
foo.png
bar.png
result.jpg
result.jpg
这篇关于如何在Python中使用OpenCV Stitcher类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!