Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cv2 python has no imread member

Tags:

I pip installed OpenCV-python. The installation seems to be fine and I tested it out on the python IDLE. It ran without any problems. I've been trying to run it on VS Code but it doesn't seem to work. The autocomplete recognizes the imread function but when I type it in it throws up an error saying cv2 has no imread member. I am using the most updated version of python

I am calling it like this:img2 = cv2.imread("C:\Biometric\min.jpg", 0)

like image 881
pasha Avatar asked Jul 30 '18 11:07

pasha


People also ask

What is cv2 Imread in python?

OpenCV-Python is a library of Python bindings designed to solve computer vision problems. cv2. imread() method loads an image from the specified file. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format) then this method returns an empty matrix.

Why can't I import cv2 in python?

Conclusion # The Python "ModuleNotFoundError: No module named 'cv2'" occurs when we forget to install the opencv-python module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install opencv-python command.

What will the cv2 Imread () return if a wrong image name is passed as argument?

Typically, the cv2. imread function will return None if the path to the input image is invalid, so be sure to double-check and triple-check your input image paths!


2 Answers

Since you are trying to executing this with VS Code, try following steps

(1) open palette on VS Code (use specifies command): CTRL + Shift + P
(2) then select "Preferences: Open Settings (JSON)" option in the palette dropdown
(3) then add the following line in the opened "settings.json" file
"python.linting.pylintArgs": ["--generate-members"]

this must work

like image 101
Amila Viraj Avatar answered Sep 21 '22 13:09

Amila Viraj


I tried so many hacks. They were not working. Someone suggested:

from cv2 import cv2

I think this is the best solution to this problem

like image 36
Neville Lusimba Avatar answered Sep 25 '22 13:09

Neville Lusimba