在具有OpenCV Python绑定的Stitcher类中使用composePanorama

在具有OpenCV Python绑定的Stitcher类中使用composePanorama,python,opencv-python,opencv-stitching,Python,Opencv Python,Opencv Stitching,我试图估算一些图像的变换,并在python中使用stitcher.estimateTransform()和stitcher.composePanorama()缝合它们。估计变换后,composePanorama给出如下误差: pano不是numpy数组,也不是标量数组 我尝试使用cv2.fromarray(左)将NumPy数组转换为Mat对象,但它只适用于cv,不适用于cv2。因此,如何在cv2中将这个numpy转换为MAT数组。我没有发现任何将composePanorama与python绑定结

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

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

我尝试使用
cv2.fromarray(左)
将NumPy数组转换为Mat对象,但它只适用于cv,不适用于cv2。因此,如何在cv2中将这个numpy转换为MAT数组。我没有发现任何将
composePanorama
与python绑定结合使用的例子。对于此错误的任何解决方案或使用OpenCV Python绑定的
stitcher.estimateTransform()
示例,我们将不胜感激

注意:尽管OpenCV Python绑定中的缝合类不完整(因为是自动生成的绑定),
帮助(cv2.createStitcher())
证明它包含
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绑定可以使用它。因此,我能看到的唯一解决方案是:

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

尽管我很高兴如果其他人能够发布一个答案,说明如何在Python中实现这一点,而无需完成上述复杂任务。

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

  • 下载opencv
  • 导航到opencv主控/模块/缝合/包含/opencv2/stitching.hpp
  • 在希望能够在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

    有关更多信息,请参阅和