Processing: Capturing faces FIX

In my last post about capturing faces I had the problem that the output of each face captured was constantly being overwritten and I could only have 4 faces saved at once. I finally managed to work out a way around this, changing the name of each image saved so that it isn’t over written and are each saved with unique names.

//Before the setup
int number = 0 //number of picture 

//.... below written in the draw

// only runs if a face is seen
  // captures a face in the box
  // start timer
  if (passedTime > totalTime) {
    number++; // adds number to picture so they count up and not overwrite
    if (faces.length >= 1) {
      face1 = get(faces[0].x, faces[0].y, faces[0].width, faces[0].height);
      String number1 = "1_" + number + ".jpg";;
      if (faces.length >= 2) {
        face2 = get(faces[1].x, faces[1].y, faces[1].width, faces[1].height);
        String number2 = "2_" + number + ".jpg";;
        if (faces.length >= 3) {
          face3 = get(faces[2].x, faces[2].y, faces[2].width, faces[2].height);
          String number3 = "3_" + number + ".jpg";
          if (faces.length >= 4) {
            face4 = get(faces[3].x, faces[3].y, faces[3].width, faces[3].height);
            String number4 = "4_" + number + ".jpg";
    println( " 5 seconds have passed! " );
    savedTime = millis(); // Save the current time to restart the timer!

Inside the timer still I have a new variable called ‘number’ which is the number of the image being taken. Every 5 seconds a value of 1 is added onto number making it count up each time the timer runs. This value is used in the name of the image being saves so that it changes each time.

For each image a string is created. For example with the first face it would output ‘1_1.jpg’, 1_2.jpg’, 1_3.jpg’ etc. continually counting until stopped.

With this there are still only 4 PImages in Processing that are continually being updated, it is just the name of the image being saved which is changed. This still means there are only 4 running images in processing and once it has been saved and overwritten, it isn’t seen by processing anymore. I may be able to save the images into an array instead or simply add more image variables but for now this will stay until I work out the best course of action.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: