From the Bench… EP61a – 8266, 32 and other numbers – NOTES
Here’s the Python code for the time-lapse mentioned in the episode. Make sure to check your paths! Ensure you’re pointing to your correct capture directory and that the directory exists (I saved this as Desktop/timelapse).:
import time
import picamera
VIDEO_DAYS = 1
FRAMES_PER_HOUR = 60
FRAMES = FRAMES_PER_HOUR * 24 * VIDEO_DAYS
def capture_frame(frame):
with picamera.PiCamera() as cam:
time.sleep(2)
cam.capture('/home/pi/Desktop/timelapse/frame%03d.jpg' % frame)
# Capture the images
for frame in range(FRAMES):
# Note the time before the capture
start = time.time()
capture_frame(frame)
# Wait for the next capture. Note that we take into
# account the length of time it took to capture the
# image when calculating the delay
time.sleep(
int(60 * 60 / FRAMES_PER_HOUR) - (time.time() - start)
)