[英]"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__ "抛出错误:“回溯(最近一次调用最后一次):文件“D:/Python/openCV/Basic_Video/Basic.py”,第 4 行,以 cv2.VideoCapture(0) 作为上限:AttributeError: __enter__ ”
The with
keyword is not supported for VideoCapture
. VideoCapture
不支持with
关键字。 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 如何使用 Opencv python 在视频流中逐帧处理视频图像
https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html
cv2.videocapture.read() does not return a numpy array cv2.videocapture.read() 不返回一个 numpy 数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.