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

2024-05-20 00:38:45 发布

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

(我在mac os 10.8.5上)

我正在使用Python 3(通过jupyter笔记本)并尝试import cv2

我成功地输入了import cv2,但是当我输入im_g = cv2.imread("smallgray.png", 0)时,会得到以下错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-5eb2880672d2> in <module>()
----> 1 im_g = cv2.imread("smallgray.png", 0)

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

我还检查了dir(cv2),得到:

['__doc__', '__loader__', '__name__', '__package__', '__path__', '__spec__'

我想很多函数都丢失了。。。 是因为opencv安装错误吗? 事实上,为了得到opencv我费了很大的劲,我想我安装了太多次了,而且通过终端安装的方式也不尽相同。(brewpip

我应该卸载opencv并重新开始吗?我该怎么做才好?

Thx提前


Tags: importpngosmac错误笔记本jupytercv2
2条回答

检查:

brew list | grep opencv

如果未安装,请尝试:

brew install opencv

cv2.cv2.imread()

这在大多数情况下都应该有效。另外,看看here

相关问题 更多 >