python - 在python中创建延时图像

标签 python opencv timelapse

以下代码从网络摄像头捕获图像,并将其保存到磁盘中。我想编写一个程序,该程序可以每30秒自动捕获一次图像,直到12个小时为止。最好的方法是什么?

import cv2     
cap = cv2.VideoCapture(0)
image0 = cap.read()[1]
cv2.imwrite('image0.png', image0)

以下是基于@John Zwinck答案的修改,因为我还需要将每30秒捕获的图像写入磁盘并命名为捕获时间:
import time, cv2
current_time = time.time()
endtime = current_time + 12*60*60
cap = cv2.VideoCapture(0)
while current_time < endtime:    
    img = cap.read()[1]
    cv2.imwrite('img_{}.png'.format(current_time), img)
    time.sleep(30)

但是,以上代码每次只能写入前一个文件的最后一个文件。寻找它的改进。

最佳答案

import time
endTime = time.time() + 12*60*60 # 12 hours from now
while time.time() < endTime:
    captureImage()
    time.sleep(30)

关于python - 在python中创建延时图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22116071/

相关文章:

来自具有长卡住尾端的源的 FFmpeg 延时

python - 具有共享内存复杂对象的多处理大型 XML 文件

javascript - Ajax + Flask 用于通知下拉列表

python-3.x - OpenCV 通过矩阵比较值进行错误级别分析

opencv - 简单但不是 opencv 中的基本背景减法?

python - 将 pandas 数据帧格式从宽更改为长,类似于 pd.melt

python - Spark MLLIB LDA 主题矩阵的输出是什么?

python - 延时图像的亮度/直方图归一化

Javascript 延时效果 : displaying 30 images/second (read for more detail)