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 & HelpVideo Capture,  Movie Playback,  Vision Libraries › Need help for a facetracking (OpenCv) program
Page Index Toggle Pages: 1
Need help for a facetracking (OpenCv) program (Read 3947 times)
Need help for a facetracking (OpenCv) program
Nov 29th, 2008, 7:38pm
 
hello dear community


I'm working on a face substitution program using OpenCv and as i'm new on Processing , i need some help Smiley

For the start i used the example of tracking of the OpenCv library  http://ubaa.net/shared/processing/opencv/

This program detect the face and then it show a picture over this face.A random pictures should appear each time the program detect a new face and show it until the face disapear but now it show a random picture on each draw loop and i don't see how can i change this , i've tried differents methods but i always arrived at quite the same result.

so i'm sure that one of this great community could be able to help me , here is my code :



import hypermedia.video.*;


PImage[] images = new PImage[13];
OpenCV opencv;

// contrast/brightness values
int contrast_value    = 0;
int brightness_value  = 0;




void setup() {

   //size( 500, 375 );
   size(640,480);

   opencv = new OpenCV( this );
   opencv.capture( width , height );                   // open video stream
   opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );  // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml"


   // print usage
   println( "Drag mouse on X-axis inside this sketch window to change contrast" );
   println( "Drag mouse on Y-axis inside this sketch window to change brightness" );
   
   
   //chargement des images
   images[0] = loadImage("face1.gif");
   images[1] = loadImage("face2.gif");
   images[2] = loadImage("face3.gif");
   images[3] = loadImage("face4.gif");
   images[4] = loadImage("face5.gif");
   images[5] = loadImage("face6.gif");
   images[6] = loadImage("face7.gif");
   images[7] = loadImage("face8.gif");
   images[8] = loadImage("face9.gif");
   images[9] = loadImage("face10.gif");
   images[10] = loadImage("face11.gif");
   images[11] = loadImage("face12.gif");
   images[12] = loadImage("face13.gif");
   
}


public void stop() {
   opencv.stop();
   super.stop();
}



void draw() {
   background(0);
   
   // grab a new frame
       opencv.read();
   
   // and convert to gray
   //opencv.convert( GRAY );
   
   // flip horizontally
   opencv.flip( OpenCV.FLIP_HORIZONTAL );
 
   opencv.contrast( contrast_value );
   opencv.brightness( brightness_value );

   // proceed detection
   Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 20, 20 );

   // display the image
   image( opencv.image(), 0, 0 );

   // draw face area(s)
   noFill();
   stroke(255,0,0);
   int index = int(random(images.length));
   for( int i=0; i<faces.length; i++ ) {
       
       rectMode(CENTER);
       //rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
       image (images[index],faces[i].x, faces[i].y, faces[i].width, faces[i].height );
       
 }
 println(frameRate);
}



/**
* Changes contrast/brigthness values
*/
void mouseDragged() {
   contrast_value   = (int) map( mouseX, 0, width, -128, 128 );
   brightness_value = (int) map( mouseY, 0, width, -128, 128 );
}



also i'm sure it could be improved (automatic filling for the " images" array and performance), or if the images used where smaller will it change something ?  

if u have an idea plz help a noob Smiley


Re: Need help for a facetracking (OpenCv) program
Reply #1 - Oct 18th, 2009, 5:29am
 
Hi haarlinsh,
How did you go with this? I'm trying to do something similar - a kind of augmented mirror that uses face tracking. I tried out your code and it worked fine with a few adjustments but the imported image quality is fairly shaky and unreliable.

I'm keen to learn more about 3D face tracking and I'd like to know where to go on these forums (or elsewhere) to find others who might have explored similar stuff.

If you could point me in the right direction I'd appreciate it.
Re: Need help for a facetracking (OpenCv) program
Reply #2 - Jun 2nd, 2010, 7:26am
 
Hi rubix i m looking at a similar area,
but i want face tracking to detect a face and then 'highlight' that face as a detected part of the camera
then it s feed to the display- the second part NO PROBLEM but the first half im new to processing

any ideas??thanks
Page Index Toggle Pages: 1