From charlesreid1

No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
https://player.vimeo.com/video/132752156
https://player.vimeo.com/video/132752156


==Raspberry Pi Timelapse Photo==
=Timelapse Scripts=


===Software===
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.


Since I hadn't connected my Pi to the net in a while, the first thing I did was to update the package manager:
==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'''


<pre>
<pre>
sudo apt-get update
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)
</pre>
</pre>


Next, I upgraded the operating system:
==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'''


<pre>
<pre>
sudo apt-get dist-upgrade
import subprocess
</pre>
from datetime import datetime
import time
import os


With all of the updating and upgrading out of the way, I moved on to the actual Raspberry Pi camera itself. There is a Python module to control the Pi camera, available through aptitude:
lapse_dir = datetime.strftime(datetime.now(),"timelapse_%Y%m%d-%H%M%S")
subprocess.call(['mkdir',lapse_dir])


<pre>
while True:
sudo apt-get install python-picamera python-picamera-docs
 
</pre>
    prefix = datetime.strftime(datetime.now(),"%Y%m%d-%H%M%S")
    filename = lapse_dir+"/"+prefix+".jpg"


However, I was still not able to use my camera, because I had to run the Raspberry Pi configuration program. To run it:
    subprocess.call(['fswebcam','-r','1280x1024','--rotate','90','--no-banner',filename])


<pre>
    print "Saving photo to %s"%(filename)
sudo raspi-config
</pre>


You enable the Raspberry Pi camera in the configuration menu.
    time.sleep(2)


===Setup===
</pre>


The setup I had used one of [http://www.adafruit.com/products/1367 these] as the camera. This is a whopping 5 MP, which is as good as a point-and-shoot, except it's extremely tiny. I was able to get it hooked up to my Raspberry Pi and working just fine with the above steps.
==SimpleCV==


You can use Python code to trigger the camera to take a picture, and you can specify a filename to save to. Here's a quick script I hacked together to take a picture every 2 seconds, and save it to sequentially-numbered files (0001.jpg, 0002.jpg, etc.):
{{Main|SimpleCV}}


<source lang="python">
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:
# pic.py


import picamera
<pre>
from SimpleCV import Camera
import os
import time
import time
from datetime import datetime


camera = picamera.PiCamera()
cam = Camera()
time.sleep(0.1)
 
lapse_dir = datetime.strftime(datetime.now(),"timelapse_%Y%m%d-%H%M%S")
os.system('mkdir '+lapse_dir)


i = 0
while True:
while True:


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


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


    i += 1
     time.sleep(2)
     time.sleep(2)


</source>
</pre>
 
=Flags=
 
{{PiFlag}}


To run this, I use screen. I log in remotely, then run the <code>screen</code> command. In that screen I run <code>python pic.py</code>. It will print out as it progresses. Running it with screen allows you to disconnect and leave the Pi unattended.
[[Category:Raspberry Pi]]
[[Category:Timelapse]]
[[Category:Photography]]

Latest revision as of 06:14, 19 August 2016

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