python - 如何在 OpenCV Python Stitcher 类中设置全景模式?

标签 python opencv image-stitching

基于 this question/answer ,我一直在尝试在 python 中使用 OpenCV 的 Stitcher 类。我的代码与答案中的基本相同。

import cv2

stitcher = cv2.createStitcher(False)
foo = cv2.imread("D:/foo.png")
bar = cv2.imread("D:/bar.png")
result = stitcher.stitch((foo,bar))

cv2.imwrite("D:/result.jpg", result[1])

问题是我想将模式从全景更改为扫描。 In the c++ documentation, create 方法有一个输入模式。然而,Python 中的 createStitcher 类只需要一个输入——是否尝试 gpu。有没有办法在 Python 中指定模式?

当我尝试 createStitcherScans 时,出现错误

stitcher = cv2.createStitcherScans(False)
"AttributeError: 'module' object has no attribute 'createStitcherScans'"

我确实找到了 this GitHub issue这似乎是相关的,关于 Python 绑定(bind)丢失了一些东西。但这超出了我的理解,我不确定如何编辑 opencv 代码以正确执行此操作。我尝试将其添加到 stitching.hpp 中:

typedef Stitcher::Mode Mode;

但是什么也没发生。 createStitcher(1, False) 仍然给我属性错误。任何帮助将不胜感激。

最佳答案

这已在 Open CV 4 中解决(至少在我运行的 4.1.0 中)。您现在可以将 mode 指定为 cv2.Stitcher.create 的关键字参数:

stitcher = cv2.Stitcher.create(mode = 1)

似乎还没有移植不同模式的枚举标签,但它适用于数字。 PANORAMA0SCANS1,定义为 here .

请注意,如果您正在使用 Google Colab,那么您可以像这样更改 Open CV 的版本:

!pip3 install opencv-python==4.1.0.25

关于python - 如何在 OpenCV Python Stitcher 类中设置全景模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50595573/

相关文章:

python - 基于其他行的过去值到当前值的新行

python - BeautifulSoup:从 html 获取 css 类

python - 分析图像中每个子窗口的更快方法?

c++ - 使用 unique_ptr 和自定义删除器包装 C 代码

Python Mechanize 登录 Facebook cookie 错误

python - 如何使用 rdflib(或纯 sparql)访问 rdf 列表的成员

c - tic-tac-toe 使用 opencv 但我可以在识别游戏板时停止

c++ - 在 OpenCV 中将两个网络摄像头画面拼接在一起

image - 实时视频(图像)拼接

c++ - OpenCV WarpPerspective 问题