【问题标题】:i use opencv version 4 and python version 3.how can i run this code我使用 opencv 版本 4 和 python 版本 3。如何运行此代码
【发布时间】:2019-11-17 16:12:55
【问题描述】:
#  White region shows sure foreground area
dist_transform = cv2.distanceTransform(opening,cv2.cv.CV_DIST_L2,5)
ret, sure_fg = cv2.threshold(dist_transform,0.7*dist_transform.max(),255,0)`enter code here`

plt.imshow(sure_fg,cmap='gray')
plt.axis('off')
plt.show()

此代码给出以下错误:

文件“C:/Users/Mahbuba/Desktop/brine.py”,第 90 行,在 dist_transform = cv2.distanceTransform(opening,cv2.cv.CV_DIST_L2,5)

AttributeError: 模块 'cv2.cv2' 没有属性 'cv'

【问题讨论】:

  • 这看起来像是一个导入命名问题。请编辑您的问题,以包括您执行 import 语句的脚本行。

标签: python opencv


【解决方案1】:

您的代码中的cv2.cv.CV_DIST_L2 应为cv2.DIST_L2

【讨论】:

    最近更新 更多