簡體   English   中英

“with”關鍵字不適用於python中的“cv2.VideoCapture(0)”

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

代碼:

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__

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM