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()

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐