[英]Using composePanorama in Stitcher class with OpenCV-Python bindings
I'm trying to estimate transform for some images and stitch them using stitcher.estimateTransform()
and stitcher.composePanorama()
in python. 我试图估计一些图像的变换并使用python中的stitcher.estimateTransform()
和stitcher.composePanorama()
进行stitcher.composePanorama()
。 After estimating transform, composePanorama gives the error as below: 估计转换后,composePanorama给出以下错误:
pano is not a numpy array, neither a scalar pano不是numpy数组,也不是标量
I tried to convert NumPy Array into a Mat object using cv2.fromarray(left)
, but it only works for cv, not cv2. 我试图使用cv2.fromarray(left)
将NumPy Array转换为Mat对象,但它仅适用于cv,不适用于cv2。 Therefore how can I convert this numpy to MAT array in cv2. 因此,如何在Cv2中将此numpy转换为MAT数组。 I don't find any examples of using composePanorama
with python bindings. 我找不到将composePanorama
与python绑定一起使用的任何示例。 Any solution for this error or example of using stitcher.estimateTransform()
with OpenCV-Python bindings would be appreciated. 对于此错误的任何解决方案,或使用带有OpenCV-Python绑定的stitcher.estimateTransform()
示例,将不胜感激。
Note : Although Stitching class in OpenCV-Python bindings is not complete (beacuse of auto-generated bindings), help(cv2.createStitcher())
demonstrates that it contains composePanorama()
and estimateTransform()
. 注意 :尽管OpenCV-Python绑定中的help(cv2.createStitcher())
类不完整(由于自动生成的绑定),但help(cv2.createStitcher())
演示它包含composePanorama()
和composePanorama()
estimateTransform()
。
Note : I can use stitcher.stitch()
without any problems, but using stitcher.stitch()
does not help me, because I'm trying to not calculate the transform for each iteration in the main loop. 注意 :我可以毫无问题地使用stitcher.stitch()
,但使用stitcher.stitch()
不会有帮助,因为我试图不计算主循环中每次迭代的变换。
My simple code : 我的简单代码:
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])
I have the same problem. 我也有同样的问题。 From what I can see, composePanorama
has two overloads. 从我可以看到, composePanorama
有两个重载。
CV_WRAP Status composePanorama(OutputArray pano);
Status composePanorama(InputArrayOfArrays images, OutputArray pano);
It's the second overload that we need, as the pano
is an output parameter, which in Python is given as a return value. 这是我们需要的第二个重载,因为pano
是输出参数,在Python中将其作为返回值给出。 Unfortunately, the second overload is not marked by CV_WRAP
which would make it available to the Python bindings. 不幸的是,第二个重载没有用CV_WRAP
标记,这将使其可用于Python绑定。 So the only solutions I can see are: 因此,我只能看到的解决方案是:
CV_WRAP
(I'm not sure it is actually as simple as that) 从源代码自己构建Open CV并将功能标记为CV_WRAP
(我不确定它实际上是否是如此简单) Although I'll be very happy if someone else can post an answer showing how to achieve this in Python without going through the complex tasks above. 尽管如果其他人可以发布答案而不显示上面的复杂任务的情况下如何在Python中实现此目标,我将感到非常高兴。
To use stitcher.estimateTransform()
and stitcher.composePanorama()
you will need to 要使用stitcher.estimateTransform()
和stitcher.composePanorama()
您需要
Then to build the python module: 然后构建python模块:
cd ~/opencv
mkdir build
cd build
cmake ../
make
sudo make install
Then move the module to your virtual environment from wherever it was installed to. 然后将模块从安装位置移动到虚拟环境。 In my case that was /usr/local/lib/python3.7/site-packages/cv2. 在我的情况下是/usr/local/lib/python3.7/site-packages/cv2。
See https://www.pyimagesearch.com/2018/08/17/install-opencv-4-on-macos/ and https://docs.opencv.org/4.1.0/da/d49/tutorial_py_bindings_basics.html and https://docs.opencv.org/4.1.1/da/df6/tutorial_py_table_of_contents_setup.html for more info. 参见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.