python opencv 定时器 摄像头自动截图小程序

import threading
import cv2
global timer
import sys

def shot_img():
    global num
    success, frame = cameraCapture.read()
    path = "H://pythonr"
    cv2.imwrite( path +'a[num]' + '.jpg', frame)
    print(num)
    num += 1
    if num==10:
        cameraCapture.release()
        cv2.destroyAllWindows()
        sys.exit()
    timer = threading.Timer(1, shot_img)
    timer.start()

if __name__ == '__main__':
    num=0
    cameraCapture = cv2.VideoCapture(0)
    timer = threading.Timer(1,shot_img)
    timer.start()

你可能感兴趣的:(OpenCV)