简体   繁体   中英

How can I fix 'openCV has no attribute VideoCapture' in 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__ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM