简体   繁体   English

AttributeError: 模块“cv2”没有属性“createStereoBM”

[英]AttributeError: module 'cv2' has no attribute 'createStereoBM'

I tried to run code from the OpenCV docs for creating a disparity image from left and right stereo images, but it gives me an error.我试图运行 OpenCV 文档中的代码来从左右立体图像创建视差图像,但它给了我一个错误。 Here is the code I ran.这是我运行的代码。

import cv2
from matplotlib import pyplot as plt

imgL = cv2.imread(r'D:\left.png', 0)
imgR = cv2.imread(r'D:\right.png', 0)

stereo = cv2.createStereoBM(numDisparities=16, blockSize=15)
disparity = stereo.compute(imgL, imgR)
plt.imshow(disparity, 'gray')
plt.show()

I am getting an error in the line我在行中遇到错误

stereo = cv2.createStereoBM(numDisparities=16, blockSize=15)

And this is the error这是错误

AttributeError: module 'cv2' has no attribute 'createStereoBM'

I have tried many other solutions previously listed on stackoverflow, github, and other forums but none of them seemed to work.我尝试了之前在 stackoverflow、github 和其他论坛上列出的许多其他解决方案,但似乎没有一个有效。

The link to the OpenCV documentation can be found here可以在此处找到 OpenCV 文档的链接

Any help will be appreciated.任何帮助将不胜感激。 Thanks.谢谢。

As oluwafemi-sule mentioned in the comments you just need to use cv2.StereoBM_create instead of cv2.createStereoBM and it will work正如评论中提到的oluwafemi-sule你只需要使用cv2.StereoBM_create而不是cv2.createStereoBM就可以了

在此处输入图片说明

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

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