Python3 +opencv 调用摄像头拍照保存

配置好的pycharm环境,配的是Python3.5 opencv4.1

 

上代码:

import cv2
import sys

def getImage(index,path):
    cap = cv2.VideoCapture(1)
    num = 1
    while cap.isOpened():
        ok,frame = cap.read()
        if not ok:
            break
        image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        if cv2.waitKey(1) & 0xFF == ord('c'):
            num = num+1;
            img_name = '%s/%d.jpg' % (path, num)
            cv2.imwrite(img_name,frame)
        cv2.imshow('getFaceIamge',frame)
    cap.release()
    cv2.destroyAllWindows()

if __name__ == '__main__':

    getImage(0,'保存目标目录')

你可能感兴趣的:(python3)