Skip to content

Instantly share code, notes, and snippets.

@slambert
Created December 1, 2015 15:13
Show Gist options
  • Save slambert/fdc5ce5150a86942aa4d to your computer and use it in GitHub Desktop.
Save slambert/fdc5ce5150a86942aa4d to your computer and use it in GitHub Desktop.
Face Detection for Erinn - only works with Processing 2
import gab.opencv.*; //Loads OpenCV library
import processing.video.*; // Loads video library (Capture, playback)
import java.awt.*; //Loads Java library
Capture video; // Creates a new Video/Capture Object
OpenCV opencv; // Creates a new OpenCV Object
void setup() {
size(640, 480);
video = new Capture(this, 640/2, 480/2);
opencv = new OpenCV(this, 640/2, 480/2);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
video.start();
}
void draw() {
scale(2);
opencv.loadImage(video);
image(video, 0, 0 );
noFill();
stroke(0, 255, 0);
strokeWeight(3);
Rectangle[] faces = opencv.detect();
println(faces.length);
for (int i = 0; i < faces.length; i++) {
println(faces[i].x + "," + faces[i].y);
rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
}
}
void captureEvent(Capture c) {
c.read();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment