使用OpenCVPython绑定在Stitcher类中使用composePanorama

2024-09-30 20:25:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图估计一些图像的转换,并使用python中的stitcher.estimateTransform()和{}缝合它们。估计变换后,composePanorama给出的误差如下:

pano is not a numpy array, neither a scalar

我试图使用cv2.fromarray(left)将NumPy数组转换为Mat对象,但它只适用于cv,而不是cv2。所以我如何将这个numpy转换成cv2中的MAT数组呢。{t{t>使用python绑定的示例。对于这个错误的任何解决方案,或者将stitcher.estimateTransform()与OpenCV Python绑定一起使用的例子,我们将不胜感激。在

注意:尽管OpenCV Python绑定中的缝合类并不完整(因为是自动生成的绑定),help(cv2.createStitcher())表明它包含composePanorama()和{}。在

注意:我可以毫无问题地使用stitcher.stitch(),但是使用stitcher.stitch()对我没有帮助,因为我试图不计算主循环中每个迭代的转换。在

我的简单代码:

leftStream = cv2.VideoCapture(0)
rightStream = cv2.VideoCapture(1)
left = leftStream.read()[1]
right = rightStream.read()[1]
st = cv2.createStitcher(False)
st.estimateTransform([left, right])
st.composePanorama([left, right])

Tags: rightnumpy数组cv2leftopencvststitch
2条回答

要使用stitcher.estimateTransform()stitcher.composePanorama(),您需要

  1. 下载opencvhttps://github.com/opencv/opencv
  2. 导航到opencv master/modules/stitching/include/opencv2/缝合.hpp在
  3. 在您希望能够在Python中调用的任何方法前面添加CV_WRAP。在这种情况下,这将是estimateTransform和composePanorama

然后构建python模块:

cd ~/opencv
mkdir build
cd build
cmake ../
make
sudo make install

然后将模块从安装位置移到虚拟环境中。在我的例子中是/usr/local/lib/python3.7/site-packages/cv2。在

有关详细信息,请参见https://www.pyimagesearch.com/2018/08/17/install-opencv-4-on-macos/https://docs.opencv.org/4.1.0/da/d49/tutorial_py_bindings_basics.htmlhttps://docs.opencv.org/4.1.1/da/df6/tutorial_py_table_of_contents_setup.html。在

我也有同样的问题。据我所见,composePanorama有两个重载。在

CV_WRAP Status composePanorama(OutputArray pano);
Status composePanorama(InputArrayOfArrays images, OutputArray pano);

这是我们需要的第二个重载,因为pano是一个输出参数,在Python中它是作为返回值给出的。不幸的是,第二个重载没有用CV_WRAP标记,这将使Python绑定可用。所以我能看到的唯一解决办法是:

  • 使用替代缝合实现
  • 检查丢失的CopyPoRoRAMA实现的C++代码,并在Python 在打开的CV Github上注册问题并等待更新
  • 从源代码构建opencv并将函数标记为CV_WRAP(我不确定它是否真的这么简单)
  • 在C++中代替Python

不过,如果有人能在不经历上述复杂任务的情况下用Python发布一个答案,我将非常高兴。在

相关问题 更多 >