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
Random Choice (Read 729 times)
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!

Re: Random Choice
Reply #1 - Jan 28th, 2010, 2:06pm
 
http://processing.org/discourse/yabb2/num_1217525053.html

have you get to any solution on this matter I get to the same point where you got stuck.

the face detection is already an object array, and the Rectangle object is inserted within the openCV library. i don't know how to deal with modifying a function inside a library....

anybody
Page Index Toggle Pages: 1