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.
Page Index Toggle Pages: 1
Face Tracking - Stuck in Loop (Read 564 times)
Face Tracking - Stuck in Loop
Apr 24th, 2010, 11:00pm
 
Hello All,

I have a pretty simple question. I am trying to figure something fairly basic out with the Opencv face tracking script. I am replacing the rectangle with random images. But somehow the image placement takes place in a loop so instead of replacing each face with a random image, it is going through the array randomly and showing all the faces. I can't figure out how to make it select one face from the array and keep it there until another face is detected.

I know why it is running the loop (to do the resizing), but am not sure how else to do it. Thanks!

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

OpenCV opencv;

// contrast/brightness values
int contrast_value    = 0;
int brightness_value  = 0;
PImage[] images = new PImage[4];

void setup() {

   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"

   for ( int i = 0; i< images.length; i++ )
     {
       images[i] = loadImage( "monster" + i + ".png" );  
     }

  noCursor();
}


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

void draw() {
   opencv.read();
   opencv.contrast( contrast_value );
   opencv.brightness( brightness_value );

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

   // 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++ ) {
           image(images[index], faces[i].x, faces[i].y, faces[i].width,faces[i].height);  
           
   }      
   
}
Page Index Toggle Pages: 1