python调用opencv实现读取摄像头逐帧转为图片

import cv2
import os

def register_face(filepath):
    cap =cv2.VideoCapture(0)
    i=1
    while(i<51):#读取50张图片
        ret , frame =cap.read()
        cv2.imshow('frame',frame)
        cv2.imwrite(filepath+"\\"+os.path.split(filepath)[1]+"_"+str(i)+".jpg",frame)
        print(filepath+"\\"+os.path.split(filepath)[1]+"_"+str(i)+".jpg")
        i = i+1
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cap.release()
    cv2.destroyAllWindows()

 

你可能感兴趣的:(Python)