AttributeError: 'cv2.VideoCapture' 对象没有属性 'isOpend'

问题描述 投票:0回答:1

我在将 OpenCV 与 VS Code 结合使用时遇到问题 我检查了 OpenCV 和 Python 的版本,但我不知道出了什么问题。

opencv版本为4.7.0 vscode 解释器是 python 3.9.13('base') /opt/anaconda3/bin/python 这里是 condalist opencv-contrib-python 4.7.0.72 pypi_0 pypi opencv-python 4.7.0.72 pypi_0 pypi

这是我的代码

import cv2
import sys
cap = cv2.VideoCapture(0)

if not cap.isOpend():
    print("Camera is not opend")
    sys.exit(1)
    
while True : 
    res, frame = cap.read()
    
    if not res : 
        print("Camera error")
        break
    
    cv2.imshow("frame", frame)
    
    key = cv2.waitKey(1) & 0xFF
    if key == 27:
        break
cv2.destroyAllWindows()
cap.release()

错误是:

AttributeError: 'cv2.VideoCapture' 对象没有属性 'isOpend'

python macos opencv visual-studio-code cv2
1个回答
0
投票

isOpened
-不是
isOpend
文档。我猜你是想复制这个例子然后复制错了(你为什么不直接复制粘贴?)。

© www.soinside.com 2019 - 2024. All rights reserved.