python 打开电脑摄像头拍照保存

import cv2
import os

output_dir ='/home/stt/data/camera/'
i = 1
cap = cv2.VideoCapture(0)
while 1:
    ret, frame = cap.read()
    cv2.imshow('cap', frame)
    flag = cv2.waitKey(1)
    if flag == 13://按下回车键
        output_path = os.path.join(output_dir,  "%04d.jpg" % i)
        cv2.imwrite(output_path, frame)
        i += 1
    if flag == 27://按下ESC键
        break

 

转载于:https://www.cnblogs.com/stt-ac/p/11187091.html

你可能感兴趣的:(python 打开电脑摄像头拍照保存)