hello dear community
I'm working on a face substitution program using OpenCv and as i'm new on Processing , i need some help
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