From charlesreid1

https://player.vimeo.com/video/132752156

Timelapse Scripts

There are a couple of different scripts available, depending on your hardware, what library you're using, how much control you need over your images, whether you need video, etc.

Picamera library (outmoded)

Not using this method, since I completely gave up on the picamera (the stupid little ribbon cable camera that is designed specifically for the Pi). It sucks. But if you're using it, here's a script to take timelapse photos with it:

lapse.py

import picamera
from datetime import datetime
import time
import os

camera = picamera.PiCamera()

lapse_dir = datetime.strftime(datetime.now(),"timelapse_%Y%m%d-%H%M%S")
os.system('mkdir '+lapse_dir)

while True:

    prefix = datetime.strftime(datetime.now(),"%Y%m%d-%H%M%S")
    filename = lapse_dir+"/"+prefix+".jpg"

    camera.capture(filename)
    print "Saving photo to %s"%(filename)

    time.sleep(2)

fswebcam (barely sufficient)

fswebcam is a fast simple unix utility for grabbing photos from USB webcams. This is a command line utility with very few options, but it gets the job done. Here's a sample script that shows how to set a couple of useful flags for the fswebcam program.

relapse.py

import subprocess
from datetime import datetime
import time
import os

lapse_dir = datetime.strftime(datetime.now(),"timelapse_%Y%m%d-%H%M%S")
subprocess.call(['mkdir',lapse_dir])

while True:

    prefix = datetime.strftime(datetime.now(),"%Y%m%d-%H%M%S")
    filename = lapse_dir+"/"+prefix+".jpg"

    subprocess.call(['fswebcam','-r','1280x1024','--rotate','90','--no-banner',filename])

    print "Saving photo to %s"%(filename)

    time.sleep(2)

SimpleCV

This is the optimal method, since SimpleCV provides an extremely useful set of functions for image processing. Here's a script for obtaining images using the SimpleCV library in a Python script:

from SimpleCV import Camera
import os
import time
from datetime import datetime

cam = Camera()
time.sleep(0.1)

lapse_dir = datetime.strftime(datetime.now(),"timelapse_%Y%m%d-%H%M%S")
os.system('mkdir '+lapse_dir)

while True:

    prefix = datetime.strftime(datetime.now(),"%Y%m%d-%H%M%S")
    filename = lapse_dir+"/"+prefix+".jpg"

    img = cam.getImage()
    img.save(filename)
    print "Saving photo to %s"%(filename)

    time.sleep(2)

Flags