rubix
YaBB Newbies
Offline
Posts: 4
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 ); }