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 );
}