Cool. BTW - what are you guys trying to achieve with the custom cascades?
Personally, I'm trying to automatically rotate videos playing on my laptop according to my eyes "locations" .. I basically like watching movies at night before getting asleep, and since I end up putting the laptop on the bed, I thought it'd be nice for the video to match my head's coordinates. My code still sucks, but I'm just getting started.
For this to work, you'll need to replace the code with any video of your choice (throw the file in your data folder).
//----- START ----
import hypermedia.video.*;
import java.awt.Rectangle;
import processing.video.*;
OpenCV face;
PFont font;
Movie myMovie;
int EyeAX, EyeAY, EyeBX, EyeBY, iAngle = 0;
int BigY, SmallY;
float DeltaX, DeltaY, Slope, fAngle = 0;
void setup() {
size( 960, 240 );
font = loadFont("HLN16.vlw");
myMovie = new Movie(this, "station.mov");
myMovie.loop();
face = new OpenCV(this);
face.capture (320,240);
face.cascade( "haarcascade_eye.xml" );
// opencv.cascade( "haarcascade_eye.xml" ); // load the FRONTALFACE description file
}
void draw() {
face.read();
background(200,200,200);
image ( face.image(), 0,0);
Rectangle[] faces = face.detect();
smooth();
noFill();
stroke(255,20,20,140);
textFont(font,16);
for (int j = 0; j < faces.length; j++){
if ( j ==1 ) {
smooth();
strokeWeight (1);
if ( faces[j].x < faces[j-1].x ) {
EyeAX = (faces[j].x + faces[j].width / 2);
EyeAY = (faces[j].y + faces[j].height /2);
EyeBX = (faces[j-1].x + faces[j-1].width / 2);
EyeBY = (faces[j-1].y + faces[j-1].height / 2);
}
else {
EyeAX = (faces[j-1].x + faces[j-1].width / 2);
EyeAY = (faces[j-1].y + faces[j-1].height /2);
EyeBX = (faces[j].x + faces[j].width / 2);
EyeBY = (faces[j].y + faces[j].height / 2);
}
if (EyeBY < EyeAY ) { BigY = EyeAY ; SmallY = EyeBY;} else { BigY = EyeBY; SmallY = EyeAY; }
DeltaX = EyeBX - EyeAX;
DeltaY = EyeBY - EyeAY;
Slope = DeltaY / DeltaX;
line (EyeAX, EyeAY,EyeBX, EyeBY);
line(0,BigY, 320, BigY);
line (EyeAX, EyeAY, EyeAX, BigY);
line (EyeBX, EyeBY, EyeBX, BigY);
fAngle = asin( Slope );
println (fAngle);
Troubleshoot();
}
}
DrawMovie();
}
void DrawMovie(){
pushMatrix();
translate(640,120);
rotate(-(fAngle)/2);
image(myMovie,0 - myMovie.width/2,0 - myMovie.height /2 );
popMatrix();
}
void Troubleshoot(){
text ( " AX: " + EyeAX, 10, 20);
text ( " AY: " + EyeAY, 10, 40);
text ( " BX: " + EyeBX, 90, 20);
text ( " BY: " + EyeBY, 90, 40);
text ( " dX " + DeltaX, 170,20);
text ( " dY " + DeltaY, 170,40);
text ( " s " + Slope, 10, 200);
text ( " A " + fAngle, 10, 220);
}
//---- END -----
Sadly, I'm using almost 100% of my CPU.
Cheers,
Eyas