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 & HelpSyntax Questions › how to fade detected faces when undetected
Page Index Toggle Pages: 1
how to fade detected faces when undetected (Read 907 times)
how to fade detected faces when undetected
Jan 10th, 2010, 11:18am
 
i have a sketch based on the example from face detection library from bryan chung.

when the faces are detected an image replaces the face, but when they go from detected to undetected because of either glitch or people leaving the screen i need the picture to fade away or fade in so its more consistent

anybody have any ideas on how to do this?
Re: how to fade detected faces when undetected
Reply #1 - Jan 10th, 2010, 3:17pm
 
Well you could start by using a timer to decide whether a face really has left the camera's view: when it 'loses' a face start counting. in pseudo-code:

Code:
  // set a threshold after which you decide a face is lost:
 int threshold = 1000; // i.e. 1 second

someEvent {
 // when face is lost store the time (assuming this is a one off triggered event):
 int lostTime = millis();
}

 if(millis > lostTime + threshold) {
   // face is lost - start fading...
 }


So whenever the camera loses a face start the timer and continue to draw the image at the last known location of the face.  If it's just a temporary glitch in the face tracking it will hopefully be resolved within a second and pick up where it left off - this should avoid too much flickering...

Then if a second passes and the face isn't recovered you'd fade it away.  To do that use tint() and simply reduce alpha from 255 to 0...
Re: how to fade detected faces when undetected
Reply #2 - Jan 11th, 2010, 1:52am
 
thanks for the reply!
it sounds like a pretty good idea to use a timer, but since ive never done anything with a time im a little lost.

millis i know is a function from the reference so no trouble there.

lost time is probably a variable that stores the exact time a face is lost but how it gets this time i dont know, can you explain?

here is the code i use right now:
it is modified so that it switches the faces detected out with eachother.

Code:
void drawFace() {
int k;
int [][] res = face.getFaces();
if (res.length>0) {
for (int i=0;i<res.length;i++) {
int x = res[i][0];
int y = res[i][1];
int w = res[i][2];
int h = res[i][3];
//here starts the face image thing
images[i] = get(res[i][0],res[i][1],res[i][2],res[i][3]);
k=i;
//here starts the face switching thing
if(res.length==1){
image(images[i],res[i][0],res[i][1],res[i][2],res[i][3]);
println("one face");
}else{
k=k-1;
if(k>-1){
image(images[i],res[i-1][0],res[i-1][1],res[i-1][2],res[i-1][3]);
}
}
}
}
}


it was done pretty fast so it has not proven totally reliable yet.
anyway what you tell me to do sounds really easy to implement if there is only one face, but i cant figure out how to do it with several.
Page Index Toggle Pages: 1