繁体   English   中英

在Stitcher类中将composePanorama与OpenCV-Python绑定一起使用

[英]Using composePanorama in Stitcher class with OpenCV-Python bindings

我试图估计一些图像的变换并使用python中的stitcher.estimateTransform()stitcher.composePanorama()进行stitcher.composePanorama() 估计转换后,composePanorama给出以下错误:

pano不是numpy数组,也不是标量

我试图使用cv2.fromarray(left)将NumPy Array转换为Mat对象,但它仅适用于cv,不适用于cv2。 因此,如何在Cv2中将此numpy转换为MAT数组。 我找不到将composePanorama与python绑定一起使用的任何示例。 对于此错误的任何解决方案,或使用带有OpenCV-Python绑定的stitcher.estimateTransform()示例,将不胜感激。

注意 :尽管OpenCV-Python绑定中的help(cv2.createStitcher())类不完整(由于自动生成的绑定),但help(cv2.createStitcher())演示它包含composePanorama()composePanorama() estimateTransform()

注意 :我可以毫无问题地使用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])

我也有同样的问题。 从我可以看到, composePanorama有两个重载。

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

这是我们需要的第二个重载,因为pano是输出参数,在Python中将其作为返回值给出。 不幸的是,第二个重载没有用CV_WRAP标记,这将使其可用于Python绑定。 因此,我只能看到的解决方案是:

  • 使用其他缝合方式
  • 浏览缺少的composePanorama实现的C ++代码,并在Python中自己重新实现
  • 在Open CV Github上注册问题,然后等待更新
  • 从源代码自己构建Open CV并将功能标记为CV_WRAP (我不确定它实际上是否是如此简单)
  • 使用C ++而不是Python

尽管如果其他人可以发布答案而不显示上面的复杂任务的情况下如何在Python中实现此目标,我将感到非常高兴。

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

  1. 下载opencv https://github.com/opencv/opencv
  2. 导航到opencv-master / modules / stitching / include / opencv2 / stitching.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了解更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM