简体   繁体   English

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

[英]AttributeError: module 'cv2.cv2' has no attribute 'samples'

After cloning the GitHub repo of OpenCV, I am trying to run grabcut.py but I am getting error : Traceback (most recent call last): File "grabcut.py", line 114, in img = cv.imread(cv.samples.findFile(filename)) AttributeError: module 'cv2.cv2' has no attribute 'samples'克隆 OpenCV 的 GitHub 存储库后,我尝试运行grabcut.py,但出现错误:Traceback(最近一次调用最后一次):文件“grabcut.py”,第 114 行,在 img = cv.imread(cv.samples .findFile(filename)) AttributeError: 模块 'cv2.cv2' 没有属性 'samples'

Here is the link to the file: https://github.com/opencv/opencv/blob/master/samples/python/grabcut.py这是文件的链接: https : //github.com/opencv/opencv/blob/master/samples/python/grabcut.py

samples submodule is available in opencv-python version 4.0.0.21 . samples子模块在opencv-python version 4.0.0.21 Use pip install to install that specific version, or a later version that has this submodule.使用 pip install 安装该特定版本或具有此子模块的更高版本。

pip install opencv-python==4.0.0.21

Change改变

img = cv.imread(cv.samples.findFile(fileName))

To

img = cv.imread(fileName)

as there is no cv.samples module因为没有 cv.samples 模块

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

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