Simple question: How to make a conditional in OpencvPro or JavacvPro when a face is detect?
in
Contributed Library Questions
•
1 year ago
Hello everybody,
This a simple question: How do I make a condition in OpencvPro or JavacvPro to operate when there is a face infront the camera, here is my code base in a example found in
www.mon-club-elec.fr:
- import codeanticode.gsvideo.*;
- import monclubelec.javacvPro.*;
- import java.awt.*;
- PImage imgSrc, imgDest;
- Rectangle[] faceRect;
- GSCapture cam;
- OpenCV opencv;
- // variables para la captura de video
- int widthCapture=320; // largeur capture
- int heightCapture=240; // hauteur capture
- int fpsCapture=20; // framerate (image/secondes) pour la capture video
- long millis0=0; // variable de mémorisation de millis
- void setup(){
- frameRate(30);// Images par seconde - The default rate is 60 frames per second
- size(widthCapture*2,heightCapture*2); // ouvre une fenêtre xpixels x ypixels
- background(0,0,0); // couleur fond fenetre
- cam = new GSCapture(this, widthCapture, heightCapture);
- cam.start();
- opencv = new OpenCV(this); // initialise objet OpenCV à partir du parent This
- opencv.allocate(widthCapture,heightCapture); // crée les buffers image de la taille voulue
- opencv.cascade("/usr/local/share/OpenCV/haarcascades/","haarcascade_frontalface_alt.xml"); // utilise chemin absolu Rép + nom fichier
- faceRect = opencv.detect(true);
- }
- void draw() {
- if (cam.available() == true) {
- cam.read(); // acquisition d'un frame
- imgSrc=cam.get(); // récupère l'image GS video dans Pimage
- opencv.copy(imgSrc); // charge l'image dans le buffer openCV
- image(opencv.image(), 0, 0);
- //Here is where I trying to make the condition
- Rectangle[] faces = opencv.detect();
- for(int i=0; i<faces.length; i++)
- {
- if(faces[i] == "0") println(faces[i]);
- println("FaceDetect!!!");
- }
- }
- }
Any help?
1