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)
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.
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.
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!
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With