[英]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绑定。 因此,我只能看到的解决方案是:
CV_WRAP
(我不确定它实际上是否是如此简单) 尽管如果其他人可以发布答案而不显示上面的复杂任务的情况下如何在Python中实现此目标,我将感到非常高兴。
要使用stitcher.estimateTransform()
和stitcher.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.html和https://docs.opencv.org/4.1.1/da/df6/tutorial_py_table_of_contents_setup.html了解更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.