2011.12.08

You probably know I’m a fan of Photo Booths, and while Sparkbooth is awesome software, you might want something free (and open source) so here’s “PhotoBooth” written in Processing.

This is all the code you need for the most minimal photo booth application:

/**
 * PhotoBooth.pde
 */ 
 
import processing.video.*;
Capture cam;

void setup() {
  size(1280, 720);
  cam = new Capture(this, 1280, 720);
}

void draw() {
  if (cam.available() == true) {
    cam.read();
    image(cam, 0, 0);
  }
} 

void keyPressed() {
    if (key == ' ') {  // space bar
      saveFrame("picture-####.jpg");
    }
}

Once you’ve got that, you can export it as an application from Processing.

(Note that I’m using a Logitech C910 webcam, so I’ve set the resolution to something that makes sense for that camera. If it looks weird with your camera, try 640×480 or something else.)

PhotoBooth Export Application

I generally use Mac OS X, but other operating systems are supported. This is one of the great things about Processing.

PhotoBooth Application

Over in the Finder you’ll see a standalone application named “PhotoBooth” that will run fullscreen when launched. (You can exit it by hitting the escape key.)

Spazz!

Once you launch it you’ll see some spazzy dude, wait, that’s me! You’ll probably see yourself instead.

Hit the space bar, and it’ll save a photo. Hit the space bar again and it’ll save another one. And on, and on.

PhotoBooth Photos

The photos will show up in the same folder as the application. They will have a random number in the name. It’s not sequential, but you can view by date created if you need them in order.

Here’s a more full version of the Processing code with a few extras commented out. Uncommenting them may prove useful for debugging or camera set-up.

/**
 * PhotoBooth.pde
 */ 
 
import processing.video.*;
Capture cam;

void setup() {
  size(1280, 720);

  // If no device is specified, will just use the default.
  cam = new Capture(this, 1280, 720);

  // To use another device (i.e. if the default device causes an error),  
  // list all available capture devices to the console to find your camera.
  //String[] devices = Capture.list();
  //println(devices);
  
  // Change devices[0] to the proper index for your camera.
  //cam = new Capture(this, width, height, devices[0]);

  // Opens the settings page for this capture device.
  //cam.settings();
}

void draw() {
  if (cam.available() == true) {
    cam.read();
    image(cam, 0, 0);
  }
} 

void keyPressed() {
    if (key == ' ') {  // space bar
      saveFrame("picture-####.jpg");
    }
}

And hey, I know that hitting the space bar ain’t cool… so you might want to use an awesome button instead.

This is a super-simple application, which basically takes some example code that ships with Processing and adds a bit to it. I hope to have a few more posts that talk about some changes you can make to this application. Stay tuned!

4 Responses to “Processing PhotoBooth”

  1. JYodaNo Gravatar says:

    Very nice. I wonder how difficult it would be to build an audio booth. Or an audio+photo booth. Or an audio/video booth.

  2. I haven’t looked into recording audio with Processing, only reacting to it. I’ll try to dig around.

  3. JYodaNo Gravatar says:

    It looks like it can probably be done with minim. Now I just need to learn how to use processing.. which actually looks sort of mercifully straightforward. Maybe it will be my winter break project. Thanks for the other blog post.

  4. We’ve been talking about doing a Processing class at Milwaukee Makerspace. Maybe we should actually finish the planning and pick a day to do it.

« | »

buy the button:

Buy The Button

recently at:


top recent artists: