我在将 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'