Tuesday, November 13, 2007

One Laptop Per Photographer

Jon Trowbridge gave me a B4 OLPC XO the other day, and I'm absolutely loving it. It is so much faster than my old B2, and with the latest softare it is rocking. Harper and I were chatting and collaboratively editing a document from across Chicago with zero setup. There is a relatively new activity called Pippy that includes many Python scripts that are simple (hello world, etc), fun (random pitch/sound generator), and educational. Coupled with a Run button it is a simple interactive console. It doesn't have anything for using the XO's built in camera, so I dove in to figure out what I could do. I looked at the Record activity but found its gstreamer/picture taking code very tied to how it did stuff, dependent on Gtk, etc. So using it as an example I wrote a simple Camera class that returns the raw RGB buffer, and a PixbufCamera subclass that has the exact same interface but returns a Gdk.Pixbuf. With these two classes we can write awesome, Pippy-ish scripts, like a time-lapse photography program:

from pixbuf_camera import PixbufCamera

time_lapse = 60 * 60 * 4 # Take pictures over a 4 hour period
freq = 120 # Take them every 2 minutes
camera = PixbufCamera ()

for i in range(0, time_lapse/freq):
  pixbuf = camera.takePicture ()
  pixbuf.save ("series/test_%04i.jpg" % i, 'jpeg')
  time.sleep (freq)
Using this program on the XO I captured this outside my window today (and scp'd it to my computer): I'd like to add video support and expose a bunch of gstreamer properties so you could create a time-lapse Ogg Theora video instead of JPGs. Perhaps eventually this camera API could be used by the Record activity itself. I really need to buy some mirror fragments and build a clip-on device for XOs so you can photograph things in front of it (meaning you can film something and use the computer simultaneously).

6 comments:

  1. Pretty cool.

    One minor nit, in the posted code, you've called something a frequency, when its really the period.

    ReplyDelete
  2. Wow, you're a genius, I've been trying to figure out how to access the camera for my own timelapse script! Can you elaborate on exactly where to put the scripts you referred to so we all could try this? Was the script you wrote executed inside pippy?

    Thanks!

    ReplyDelete
  3. @Timo, glad you like the idea too. I just put the scripts in /home/olpc/ and ran them from the command line (I happened to be logged into the XO via ssh). Let me know if you have any trouble getting it to run.

    ReplyDelete
  4. Gabriel: Thanks for the quick reply and great scripts. The only thing I had trouble with was that time.sleep wasn't working untill I added an "import time" line at the top of the script. The other unimportant oddity is that I could launch the script from the terminal activity on the XO but not if I were ssh'd in (from a mac).

    Thanks again and keep me informed of any more advancements. I plan on using this to create outdoor timelapses while camping, climbing and the like. To compile the movie I grabbed them via ssh and used QuickTime to generate the movie from the sequencial frames.

    ReplyDelete
  5. I think this is especially true in notebooks, because notebook graphics processors frequently have little or no memory of their own and share the main system RAM.

    ReplyDelete