Python - 如何在两个循环之间交替?

时间:2016-02-04 01:47:48

标签: python image

我很好奇如何在两个循环之间交替。第一个循环需要一组图片。第二个循环删除所有这些循环。我想拍摄照片,删除,拍摄,删除无限(或至少在很长一段时间内)。

import time
import picamera
import webbrowser
import io
import os

frames = 60
deletecount = 0

def filenames():
    frame = 0
    while frame < frames:
        yield 'image%02d.jpg' % frame
        frame += 1
    with picamera.PiCamera() as camera:
        camera.resolution = (1024, 768)
        camera.framerate = 60
        camera.start_preview()
        time.sleep(1)

        start = time.time()
        camera.capture_sequence(filenames(),use_video_port=True)
        finish = time.time() #takes 60 pics

while deletecount < frames:

    if os.path.exists("/home/pi/image%02d.jpg"%deletecount):
       os.remove("/home/pi/image%02d.jpg"%deletecount)
       deletecount += 1

0 个答案:

没有答案