Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python + opencv with PyCharm- 'opencv' has no attribute 'imread'

A similar question to mine exists, however it does not answer my question.

Here is what I am working with:

Python v. 3.6.2
opencv 1.0.1
PyCharm Community Edition 2017 .2.2
macOS Sierra Version 10.12.6

I'm trying to use imread for image processing. I've looked at the documentation and I am using the function correctly. Here is the test code that comes with the opencv library:

import opencv
img = cv.imread('background.png')
if img is None:
    print("Image not loaded!")
else:
    print("Image is loaded!")

I can see my python files and and modules in the project explorer. When I run the code, I get the following error:

/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/lmc/Desktop/pywerk/opencvpractice Traceback (most recent call last): File "/Users/lmc/Desktop/pywerk/opencvpractice", line 4, in img = cv.imread('background.png') AttributeError: module 'opencv' has no attribute 'imread'

I've tried everything from reinstalling python and the opencv module to switching python versions to 2.7 (and using the respective opencv module) and I get the same error.

Is there some sort of system configuration I could be missing? Any help would be much appreciated.

like image 840
lane Avatar asked Jun 14 '26 09:06

lane


2 Answers

maybe you should try with opencv.imread?

import opencv
img = opencv.imread('background.png')
if img is None:
    print("Image not loaded!")
else:
    print("Image is loaded!")

or alternatively import opencv as cv:

import opencv as cv
img = cv.imread('background.png')
if img is None:
    print("Image not loaded!")
else:
    print("Image is loaded!")
like image 127
Reblochon Masque Avatar answered Jun 15 '26 23:06

Reblochon Masque


For OpenCV, it should be imported as

import cv

or import cv2 (If you want to change to opencv V2.x or 3.x)

like image 39
Totoro Avatar answered Jun 15 '26 22:06

Totoro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!