赞
踩
Python 摄像头每隔多长时间拍摄照片
初学者 有什么写的不对的请见谅,请指正
import time import cv2 import datetime def get_pic(camera_idx=0,seconds=5): time_start = time.time() cap = cv2.VideoCapture(camera_idx) ret, frame = cap.read() while ret: time_start2 = time.time() #print(time_start2-time_start) if time_start2-time_start >= seconds: NowOnTxt = datetime.datetime.strftime(datetime.datetime.now(), '%m.%d-%H.%M.%S') ret, frame = cap.read() cv2.imwrite(NowOnTxt + ".jpg", frame) print("时间差:5秒") time_start = time_start2 cap.release() # try: # except KeyboardInterrupt: # # print("Interrupted!") if __name__ == '__main__': try: get_pic() except KeyboardInterrupt: print("Interrupted!")
但是有一个小问题 就是 我没法中断他 也请各位大佬批评指正。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。