Python OpenCV 调用摄像头并截图保存

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Clannad_niu/article/details/83747092

0x01 OpenCV安装 

 通过命令pip install opencv-python 安装

pip install opencv-python

0x02  示例

import cv2

cap = cv2.VideoCapture(0)        #打开摄像头

while(1):
    # get a frame
    ret, frame = cap.read()
    # show a frame
    cv2.imshow("capture", frame)     #生成摄像头窗口
    
    if cv2.waitKey(1) & 0xFF == ord('q'):   #如果按下q 就截图保存并退出
        cv2.imwrite("D:/test.png", frame)   #保存路径
        break

cap.release()
cv2.destroyAllWindows()

猜你喜欢

转载自blog.csdn.net/Clannad_niu/article/details/83747092
今日推荐