Skip to content

Instantly share code, notes, and snippets.

@atduskgreg
Created February 17, 2014 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atduskgreg/9059058 to your computer and use it in GitHub Desktop.
Save atduskgreg/9059058 to your computer and use it in GitHub Desktop.
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
Capture video;
OpenCV opencv;
void setup() {
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
}
else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(i + " " + cameras[i]);
}
video = new Capture(this, 640/2, 360/2, "FaceTime HD Camera", 30);
size(640/2,360/2);
opencv = new OpenCV(this, 640/2, 360/2);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
video.start();
}
}
void draw() {
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