“ with”关键字不适用于python中的“ cv2.VideoCapture(0)”

时间:2019-12-07 21:28:44

标签: python opencv machine-learning computer-vision computer-science

代码:

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()`

抛出错误:  “ 回溯(最近通话最近):   文件“ D:/Python/openCV/Basic_Video/Basic.py”,第4行,在     以cv2.VideoCapture(0)为上限: AttributeError:__enter __