简体   繁体   中英

"with" keyword does not work with "cv2.VideoCapture(0)" in python

code:

import cv2
import numpy as np

with cv2.VideoCapture(0) as cap:
    while True:
        ret, frame = cap.read()
        cv2.imshow("Title", frame)

        if cv2.waitKey(1):
            break

        cv2.destroyAllWindows()`

Throws error: " Traceback (most recent call last): File "D:/Python/openCV/Basic_Video/Basic.py", line 4, in with cv2.VideoCapture(0) as cap: AttributeError: __enter__ "

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