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
crop to face detect co-ordinates (Read 1799 times)
crop to face detect co-ordinates
Jan 5th, 2009, 4:33pm
 
Hi ive managed to crop a still image from my webcam giving co-ordinates but i cant work out how to do it to the co-ordinates of the rectangle which apears using face detect. any suggestions (im quite new to processing btw)

-----code-------

import processing.video.*;
import FaceDetect.*;

FaceDetect fd;
Capture cam;


int MAX = 10;

int[] x = new int[MAX];
int[] y = new int[MAX];
int[] r = new int[MAX];
int[][] Faces = new int[MAX][3];

void setup(){

 size(640,480,P3D);
 cam = new Capture(this, 640, 480);
 fd = new FaceDetect(this);
 fd.start("haarcascade_frontalface_alt.xml", width,height,30);
 stroke(255,200,0);
 
 noFill();
}

void draw(){
 if (cam.available()) {
   cam.read();
   image(cam,0,0);

   Faces = fd.face(cam);
   int count = Faces.length;
   //    println(count);
   if (count>0) {
     for (int i = 0;i<count;i++) {
       x[i] = Faces[i][0];
       y[i] = Faces[i][1];
       r[i] = Faces[i][2] * 2;
       rectMode(CENTER);
       rect(x[i],y[i],r[i],r[i]);// co-ordinates i want to
//crop to
     }
   }
 }
}

--------code------------
Re: crop to face detect co-ordinates
Reply #1 - Mar 2nd, 2009, 12:57pm
 
I solved this way:

--------8<---------


static PImage cropped;

Rectangle[] faces = imagegetted.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 30, 40 );

 if (faces.length!=0)  

            {
             
cropped=createImage(faces[0].width,faces[0].height,RGB);
cropped.copy(acquisito,faces[0].x,faces[0].y,faces[0].width,faces[0].height,0,0,faces[0].width,faces[0].height);
            }



-------8<--------------

Now the problem I have is to choose the right camera in every working condition:program works only on the computer where I compiled it.

Enjoy!
Marco
http://www.taffi.it

Re: crop to face detect co-ordinates
Reply #2 - Nov 26th, 2009, 4:26am
 
Hi Seany and Marco,
I'm trying to do the same thing. Using Marco's code snippets I'm able to save black boxes the exact size of the facetracking rectangle, but with no face in them!

Here's my code, and help would be greatly appreciated:

import hypermedia.video.*;
PImage cropped;
OpenCV opencv;
int n = 0;

// contrast/brightness values
int contrast_value    = 0;
int brightness_value  = 0;


void setup() {

 size( 320, 240 );

 opencv = new OpenCV( this );
 opencv.capture( width, height );                  
 opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );  

}

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

void draw() {

 opencv.read();
 opencv.flip( OpenCV.FLIP_HORIZONTAL );
 opencv.contrast( contrast_value );
 opencv.brightness( brightness_value );

 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);
 for( int i=0; i<faces.length; i++ ) {
   rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );

   if (faces.length!=0)  

   {

     cropped=createImage(faces[0].width,faces[0].height,RGB);
     cropped.copy(faces[0].x,faces[0].y,faces[0].width,faces[0].height,0,0,faces[0].width,faces[0].height);
   }
 }
}

void keyPressed() {
 n = n+1;
 cropped.save("final" + n + ".jpg");
}

/**
* Changes contrast/brigthness values
*/
void mouseDragged() {
 contrast_value   = (int) map( mouseX, 0, width, -128, 128 );
 brightness_value = (int) map( mouseY, 0, width, -128, 128 );
}






Re: crop to face detect co-ordinates
Reply #3 - Nov 29th, 2009, 2:06am
 
I solved my problem:
// draw face area(s)
 noFill();
 stroke(255,0,0);
 for( int i=0; i<faces.length; i++ ) {
   rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
   cropped = get( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
 }
}

void keyPressed() {
 n = n+1;
 cropped.save("final" + n + ".jpg");
}
Page Index Toggle Pages: 1