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
OpenCV face and eye detection (Read 2068 times)
OpenCV face and eye detection
Mar 5th, 2009, 12:29am
 
hello there, while trying to convert following C code into processing, I run into problem -
http://nashruddin.com/OpenCV_Eye_Detection

- how to load two opencv.cascade within setup() ? loading those during each cycle sounds too expensive.  
Re: OpenCV face and eye detection
Reply #1 - Mar 5th, 2009, 5:23pm
 
okay, my sloppy code produced a sad result, "out of memory" windows said...

Code:


import hypermedia.video.*;


OpenCV opencv;

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



void setup() {

size( 320, 240 );

opencv = new OpenCV( this );
opencv.capture( width, height ); // open video stream
// opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml"
opencv.cascade( "C:\\Program Files\\OpenCV\\data\\haarcascades\\haarcascade_frontalface_alt.xml" );

// print usage
println( "Drag mouse on X-axis inside this sketch window to change contrast" );
println( "Drag mouse on Y-axis inside this sketch window to change brightness" );

}


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



void draw() {

// grab a new frame
// and convert to gray
opencv.cascade( "C:\\Program Files\\OpenCV\\data\\haarcascades\\haarcascade_frontalface_alt.xml" );
opencv.read();
opencv.convert( GRAY );
opencv.contrast( contrast_value );
opencv.brightness( brightness_value );

// display the image
image( opencv.image(), 0, 0 );
// draw face area(s)
noFill();
stroke(255,0,0);

// proceed face detection
Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );

if ( faces.length > 0 ) {
opencv.ROI( faces[0].x, faces[0].y+(faces[0].height/5), faces[0].width, faces[0].height/3 );
opencv.cascade( "C:\\Program Files\\OpenCV\\data\\haarcascades\\haarcascade_eye.xml");
Rectangle[] eyes = opencv.detect();
opencv.ROI(null);
for( int i=0; i<faces.length; i++ ) {
rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
}
stroke(0,255,0);
fill(0);
for( int i=0; i<eyes.length; i++ ) {
rect( eyes[i].x+faces[0].x, eyes[i].y+faces[0].y+(faces[0].height/5), eyes[i].width, eyes[i].height );
}
}
delay(100);
}


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




Page Index Toggle Pages: 1