How can I fix 'openCV has no attribute VideoCapture' in python - python

I currently have opencv-python 4.5.3.56 installed and running in Python 3.8. However, whenever I try to use the library, I get the error:
Traceback (most recent call last):
File "c:/Users/ryck5/Documents/FA2021/ECEG301/camerademo/color_detection.py", line 108, in <module>
dj.open_camera()
cap = opencv.VideoCapture(0)
AttributeError: module 'opencv' has no attribute 'VideoCapture'
I also tried print(opencv.__version__), but that gave me the same error, just with version instead of VideoCapture. I've tried uninstalling and reinstalling opencv countless times, using the opencv-contrib-python library instead, but nothing has worked. Any help would be much appreciated!

opencv library is used as cv2 namespace in python environment. Most probably you have installed python-opencv and using it.
Try:
import cv2 and then use cv2.VideoCapture().
Also, this is why opencv.__version__ is giving you error as there is no opencv object or library here. Try cv2.__version__.

Related

Cannot import opencv because of circular import

When trying to import opencv in jupyter lab notebook (import cv2) i get this error:
AttributeError: partially initialized module 'cv2' has no attribute
'gapi_wip_gst_GStreamerPipeline' (most likely due to a circular
import)
I have tried installing opencv both via pip:
pip install opencv-python
than via conda-forge:
conda install -c conda-forge opencv
in different envs, also uninstalling and reinstalling.
If i try to import it via command line python i do not get any error.
I came up with a dirty fix, for the ones that are in a rush.
The error is produced by the last line (290) of the file: /.local/lib/python3.8/site-packages/cv2/gapi/__init__.py:
cv.gapi.wip.GStreamerPipeline = cv.gapi_wip_gst_GStreamerPipeline
That seems like some sort of naming adjustment. I commented out the line and the import error is gone and the library seems to work ok.

Import CV2: DLL load failed: The specified module could not be found while successful pip installation

I was working with Python 3.7 and OpenCV 4.2 in Pycharm IDE (Windows10). The system environment variables were changed by one of my co-workers by accident (we don't know what happened exactly). Then I found that my code did not work with this error!:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
Then I used this command:
pip uninstall opencv-python
pip uninstall opencv-contrib-python
pip install opencv-python
All of them executed successfully, but when I write import cv2 the above error is appeared. By the way, the system knows command Python, it shows the right path to the python.exe. Moreover, commands like import numpy works correctly! How can I fix this problem?
I found the answer! There was an extra cv2.py file in site-packages/cv2 path. So, I removed it and the code worked

Python Opencv DLL load failed - Windows 10

This is an error that I've seen in several different places but none of the listed solutions have worked for me.
I'm trying to use opencv but when I import the module I get the following error:
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
I have tried installing opencv from a pre-downloaded package, my computer has the current windows media pack and I jave run the module the depends without it listing any dependecy errors, I'm not sure what else to try at this point.
Edit: I have also tried installing opencv-contrib-python to no avail.
Let me know if you have any suggestions.
I had faced a similar issue and I solved it using:
pip install opencv-contrib-python
I updated from python 3.7.3 to python 3.7.6 and it fixed the problem. Worth a shot if you have the same issue.

imread from scipy.misc does not work on pycharm. I can't seem to install PIL either

from scipy.misc import imread
Traceback (most recent call last):
File "<input>", line 1, in <module>
ImportError: cannot import name 'imread'
If I run the first on pycharm, I get the following message. I've came across that I need to install PIL or Pillow to work with imread. However, trying to install PIL on pycharm gives me this warning.
warning I get
+) interpreter that I'm running on pycharm is:
'/Users/jeongseohyeong/anaconda3/envs/DL/bin/python' (python 3.6)
I've also seen posts that are saying pip install pil works. However, it doesn't seem to work for me (or at least it works for my jupyter notebook which is built in '/Users/jeongseohyeong/anaconda3/bin/python'). Any help would be appreciated.
Imread has been depreciated. Either roll back to scipy 1.1 so you can use it or use another module.

Install jpeg module in ubuntu

I am working on an image compression module, for that I want use jpeg library, but when I am importing it I am getting the following error.
"" import jpeg
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named jpeg
this was happening after i installed the libjpeg library also, I want use jpeg in python image compression, so can any tell me resolve the problem , how to install jpeg in ubuntu
and help me solve the error .
I believe it's recommended to use the Python Imaging Library as the jpeg module is deprecated since python 3.0. So the module you need to import:
import Image
If you still get an import error then try:
sudo apt-get install python-imaging
Documentation can be found here: http://effbot.org/imagingbook/introduction.htm
and there are some jpeg examples on that page.
I believe the problem is that you're trying to use the jpeg module in an unsupported platform. According to the documentation it's only supported in IRIX, so if you try to import it in a different platform, then you'll get the ImportError exception.

Categories