import threading
import cv2
global timer
import sys
import time
def shot_img():
global num
success, frame = cameraCapture.read()
path = "D:/Images/"
cv2.imwrite( path +str(num) + '.png', frame)
print(num)
num += 1
if num==5:
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()