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 with
keyword is not supported for VideoCapture
. All examples that I found always declare it first:
How to process images of a video, frame by frame in video streaming using Opencv python
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.