We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › not ovewriting images + wait for 30 secs
Page Index Toggle Pages: 1
not ovewriting images + wait for 30 secs (Read 2001 times)
not ovewriting images + wait for 30 secs
May 19th, 2010, 4:07am
 
Hello All,

I'm busy with an exebition were I would like to have a camera detecting faces and when a face is detected it makes a picture. After making a picture I want it to wait for 30 secs before he starts detecting faces again. What it does right now is: On every 2 sec it looks if a face is recognized, and if it's making a picture. If not he checks the next time when he reached the 2 sec. So my question is how to add a timer that basically stops the program for 30 secs.

And does anybody knows how to add pictures in stead of overwriting them (what it does right now)

Code:

int startingTime;
float multi;

import hypermedia.video.*;
import lmu.*;

int has_taken_picture_in_second;
OpenCV opencv;
int photoNo;

void setup()
{
size(320, 240);
background(#99EEAA);
startingTime = millis();

frameRate(25);
opencv = new OpenCV(this);
opencv.capture( width, height );
opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // load the FRONTALFACE description file
}

void draw()
{
opencv.read();
image( opencv.image(), 0, 0 );
// detect anything ressembling a FRONTALFACE
Rectangle[] faces = opencv.detect();

int seconds = (millis() - startingTime) / 1000;
int minutes = seconds / 60;
int hours = minutes / 60;
seconds -= minutes * 60;

println(seconds);
//println(minutes);

// maakt elke ... seconde een foto
if (seconds > 2)
{
startingTime=millis();
has_taken_picture_in_second = -1;
}

// maakt een foto wanneer een gezicht is herkent
if (seconds % 30 == 2 && has_taken_picture_in_second != seconds)
{
for( int i=0; i<faces.length; i++ )
{
has_taken_picture_in_second = seconds;
saveFrame(photoNo+".png");
photoNo++;
println("gezicht herkent!");

}

}
}//end draw


Re: not ovewriting images + wait for 30 secs
Reply #1 - May 19th, 2010, 5:24am
 
arie willem wrote on May 19th, 2010, 4:07am:
So my question is how to add a timer that basically stops the program for 30 secs.

Easy: set a boolean, like bStop, and a secondary timer variable, stopStartTime.

Upon some condition, set this bStop to true, and stopStartTime to millis().
At start of draw(), add:
Code:
if (bStop) {
if (millis() - stopStartTime < 30000) {
return; // Don't draw anything
} else {
bStop = false; // Restart drawing
}
}
}
Re: not ovewriting images + wait for 30 secs
Reply #2 - May 26th, 2010, 4:31am
 
PhiLho, thank you for your help so far.

What the timer does right now is it's starting immediately. But it had to begin after a photo has taken. And also it keeps on counting right now.

Here's te code. I hope you can help me further.

I you have the solution please can you paste the whole code Smiley  Grin

Code:
int startingTime;
float multi;
boolean bStop=true; //before setup()
int stopStartTime;
import hypermedia.video.*;
import lmu.*;

int has_taken_picture_in_second;
OpenCV opencv;
int photoNo;

void setup()
{
 size(320, 240);
 background(#99EEAA);
 startingTime = millis();
 
 frameRate(25);  
 opencv = new OpenCV(this);
 opencv.capture( width, height );
 opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );    // load the FRONTALFACE description file
}

void draw()



{
 
 opencv.read();
 image( opencv.image(), 0, 0 );
 // detect anything ressembling a FRONTALFACE
 Rectangle[] faces = opencv.detect();
 
 int seconds = (millis() - startingTime) / 1000;
 int minutes = seconds / 60;
 int hours = minutes / 60;
 seconds -= minutes * 60;

 println(seconds);
 //println(minutes);

}

 // maakt elke ... seconde een foto
 if (seconds > 2)
 {
    startingTime=millis();
    has_taken_picture_in_second = -1;
  }

 // maakt een foto wanneer een gezicht is herkent
 if (seconds % 30 == 2 && has_taken_picture_in_second != seconds)
 {
   for( int i=0; i<faces.length; i++ )
   {
has_taken_picture_in_second = seconds;
//saveFrame(photoNo+".png");
photoNo++;
println("gezicht herkent!");
   
   if (bStop) {
 if (millis() - stopStartTime < 30000) {
   return; // Don't draw anything
 } else {
   bStop = true; // Restart drawing
 }
}
   }
   
 }
}//end draw

Re: not ovewriting images + wait for 30 secs
Reply #3 - May 30th, 2010, 12:54pm
 
All right, now for the other half of this project Wink

Code:
import hypermedia.video.*;
import java.awt.Rectangle;

OpenCV opencv;
boolean pictureJustTaken = false;
int startTimer;
int interval = 20; // interval in seconds

void setup() {
 size(320,240);
 opencv = new OpenCV(this);
 opencv.capture(width,height);
 opencv.cascade(OpenCV.CASCADE_FRONTALFACE_ALT);
}

void draw() {
 opencv.read();
 image(opencv.image(),0,0);

 Rectangle[] faces = opencv.detect(1.2,2,OpenCV.HAAR_DO_CANNY_PRUNING,40,40);

 if (pictureJustTaken == false && faces.length >= 1) {
   saveFrame("/faces/" + year() + "-" + month() + "-"  + day() + " "  + hour() + "."  + minute() + "."  + second() + ".png");
   pictureJustTaken = true;
   startTimer = millis();
 }

 if (pictureJustTaken) {
   if (millis() - startTimer > (interval * 1000)) {pictureJustTaken = false;}
 }
}

public void stop() {
 opencv.stop();
 super.stop();
}
Re: not ovewriting images + wait for 30 secs
Reply #4 - May 31st, 2010, 1:17am
 
wow nice. I'm gonna put it all together for the exhibition!! Thanks for y'r help.

Page Index Toggle Pages: 1