Processing 2.0 : Photo Booth Sketch

Sunday, FUN DAY, in the spirit of random code experiments, I script’d a simple Photo Both app in Processing. It’s a base idea that I plan to expand on a bit further. Here are some screen shots of the application in action.

Photo Booth v.1.0

(1) The start screen. The application starts a video capture using the “FaceTime HD Camera” on my Mac. The message informs the user of next steps, “Press the ‘c’ key to capture image”, (video feed).

capture_msg

(2) The capture screen. After pressing the c key, the application captures a frame from the video feed and informs the user of their options, “Press ‘s’ key to save, Press ‘v’ key to return to video.”, (start screen);

save_img_msg

(3) The Save screen. After pressing the s key, the application saves the captured image into a folder “/images/photo_booth/” with a unique file name of “Screen_Shot_2013_4_7_10_2_36_.jpg” (Screen_Shot+date+time) and returns the user to the start screen.

saving_msg

(4) The final output.

Screen_Shot_2013_4_7_10_2_36_

Here’s the code for the application, minus the 3 custom classes. I’ve zipped the app up and have made it available for download at the bottom of this post.

/*
Manuel Gonzalez
www.codingcolor.com
Processing Photo Booth v.1.0
*/

import processing.video.*;

Capture webcam;
PImage capture_img;
TextField tField;
Timer save_msg_timer;
TimeStamp timeStamp;

int video_width;
int video_height;

boolean render_cam;
boolean render_capture;
boolean render_textfield;
boolean app_saving;

String folder_path  = "images/photo_booth/Screen_Shot";
String file_format  = ".jpg";
int TIMER_DURATION = 1500;

void setup()
{
  size(640,500);
  smooth();

  video_width = 640;
  video_height = 480;

  webcam = new Capture(this, video_width, video_height,"FaceTime HD Camera (Built-in)", 30);
  webcam.start();

  capture_img = new PImage(video_width, video_height);

  tField = new TextField("Press the c key to capture image.",width/2,496,18,255);

  timeStamp = new TimeStamp();

  save_msg_timer = new Timer(TIMER_DURATION);
  render_cam = true;
  render_textfield = true;
  app_saving = false;
}

void draw()
{
  background(0);
  renderCam();
  renderCapture();
  renderTextField();
  renderSaveTimer();

}
void keyReleased()
{
  switch(key){
    case 'c':
    captureCam();
    break;
    case 's':
    if(render_capture)
    {
    saveImage();
    }

    break;
    case 'v':

     restartCam();
     tField.setMsg("Press the 'c' key to capture image.");
    break;
    default:
    break;
  }
}
void captureCam()
{
  if(render_capture)
  {
    return;
  }
  println("capture image");
  capture_img = webcam.get();
  render_cam = false;
  webcam.stop();
  render_capture = true;
  tField.setMsg("Press 's' key to save, Press 'v' key to return to video.");
}
void saveImage()
{
  if(app_saving)
  {
    return;
  }
  println("save image");

  tField.setMsg("SAVING...");
  save_msg_timer.start();
  app_saving = true;

  String[] sFile = new String[3];
  sFile[0] = folder_path;
  sFile[1] = timeStamp.getTimestamp("_");
  sFile[2] = file_format;
  String save_path = join(sFile, "_");

  println(save_path);

  capture_img.save(save_path);
  restartCam();

}
void restartCam()
{

  if(render_cam)
  {
    return;
  }

  println("restart cam");
  render_capture = false;
  webcam.start();
  render_cam = true;
}
void renderCapture()
{
  if(render_capture){

    image(capture_img,0,0);
  }
}
void renderTextField()
{
  if(render_textfield)
  {
    tField.display();
  }

}
void renderCam()
{
 if(webcam.available())
  {
    webcam.read();
  }

  if(render_cam)
  {
        image(webcam,0,0);
  }

}
void renderSaveTimer()
{
  if(app_saving)
  {
    if(save_msg_timer.isFinished())
    {
      app_saving = false;
      tField.setMsg("Press the 'c' key to capture image.");
    }
  }
}

DOWNLOAD – Processing : Photo Booth (359)

2 thoughts on “Processing 2.0 : Photo Booth Sketch

    • December 2, 2013 at 12:17 pm
      Permalink

      Sorry for the late reply did you try:
      webcam = new Capture(this, video_width, video_height, 30);
      webcam.start();

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: