python之opencv读取摄像头帧图像

import cv2 as cv
cap = cv.VideoCapture(0)
if not cap.isOpened():
    print("Cannot open camera")
    exit()
while True:
    # 逐帧捕获
    ret, frame = cap.read()
    # 如果正确读取帧,ret为True
    if not ret:
        break
    # 显示结果帧
    cv.imshow('frame', frame)
    if cv.waitKey(1) == ord('q'):
        break
# 完成所有操作后,释放捕获器
cap.release()
cv.destroyAllWindows()

原文链接:

https://baijiahao.baidu.com/s?id=1730498444619430964&wfr=spider&for=pc

你可能感兴趣的:(Python,opencv入门,opencv,python,计算机视觉)