Giova
YaBB Newbies
Offline
Posts: 9
Random Choice
Jul 31st , 2008, 7:24pm
Hi all! This is a modified version of OpenCv face recognition sketch: Here is the code: import hypermedia.video.*; PFont fontA; PImage img; OpenCV opencv; // valori contrast/brightness int contrast_value = 0; int brightness_value = 0; String sFrase; void setup() { fontA = loadFont ("Apple-Chancery-18.vlw"); size( 640,480 ); PImage a; // Dichiara oggetto "a" del tipo PImage img = loadImage("Max.png"); // Carica l'immagine nel programma opencv = new OpenCV( this ); opencv.capture( width, height ); // apri video stream opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // carica detection description, -> front face detection : "haarcascade_frontalface_alt.xml" sFrase = fScegliFrase(); } void draw() { opencv.read(); opencv.flip( OpenCV.FLIP_HORIZONTAL); Rectangle[] faces = opencv.detect( 1.1, 2, OpenCV.HAAR_DO_CANNY_PRUNING,90,90 ); image( opencv.image(), 0,0 ); for( int i=0; i<faces.length; i++ ) { // image(img, faces[i].x+180, faces[i].y-200); textFont(fontA, 18); text(sFrase, faces[i].x+90,faces[i].y-100); } } int fRandomizza (int n) { int nRisultato = int (random (n)); println(nRisultato); return nRisultato; } String fScegliFrase () { String[] frasi = {"Ma che cacchio fai?", "Ma che cacchio pensi?", "Dio cane", "Sono brutto", "cacchio", "vivs l'olio f'oliva"}; int frasiR = fRandomizza (frasi.length); String sFraseScelta = frasi[frasiR]; return sFraseScelta; } public void stop() { opencv.stop(); super.stop(); } In this sketch, when processing recognize a face select a random string from the array, but when a new face is recognize, the string displayed is ever the same. I want that every time that a new faces was recognized, a different array string was displayed. For example: processing recognize the first face and take the random value of array position (for example "3") that contains the string "Hello". When a new face was recognize, processing select another different value from array position: ex. array position 5 witch contain the string "House". Anyone can help me??? Excuse me for my baaaaaad english!