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

2024-09-28 16:22:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图运行OpenCV文档中的代码,从左右立体图像创建视差图像,但它给了我一个错误。这是我运行的代码。在

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()

我的线路有个错误

^{pr2}$

这就是错误

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

我尝试过很多其他的解决方案,以前在stackoverflow、github和其他论坛上都列出过,但似乎没有一个有效。在

OpenCV文档的链接可以找到here

任何帮助都将不胜感激。谢谢。在


Tags: 代码文档图像importpng错误pltcv2