Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

opencv

(i'm on mac os 10.8.5)

I'm using Python 3 (through jupyter notebook) and trying to import cv2

I did import cv2 succefully, but when I type im_g = cv2.imread("smallgray.png", 0) I get this error:

---------------------------------------------------------------------------
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'

I also checked dir(cv2) and I get:

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

I guess a lot of functions are missing... Is it due to a wrong opencv installation ? Actually I struggled a lot to get opencv and I guess I installed it 'too many times' and different ways via Terminal. (brew, pip)

Should I uninstall opencv and start over ? How can I do this properly ?

Thx in advance

like image 895
Samuel Avatar asked Dec 17 '17 16:12

Samuel


1 Answers

It might be the case that you installed it in the wrong way. In my case as well, I installed OpenCV wrongly so I uninstalled it completely then reinstalled it which caused it to work.

Please notice the sequence of uninstalling and installing:

Uninstall:

pip uninstall opencv-python
pip uninstall opencv-contrib-python

Install:

pip install opencv-contrib-python
pip install opencv-python
like image 65
Satyam Annu Avatar answered Sep 30 '22 02:09

Satyam Annu