Skip to content

Instantly share code, notes, and snippets.

@MasonSlover
Last active September 29, 2020 17:57
Show Gist options
  • Save MasonSlover/25a3ed67dbbfc78718172f356278ffc9 to your computer and use it in GitHub Desktop.
Save MasonSlover/25a3ed67dbbfc78718172f356278ffc9 to your computer and use it in GitHub Desktop.
A .pde framework for facial tracking and augmentation projects
import gab.opencv.*;
import processing.video.*;
import java.awt.Rectangle;
OpenCV opencv;
Rectangle[] faces;
Capture cam;
//Variables representing the location of center of face
int faceX = 0, faceY = 0;
PImage image;
void setup() {
background(0);
size(640, 480);
//initalize webcam
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(cameras[i]);
}
cam = new Capture(this, cameras[0]);
cam.start();
}
}
void draw() {
cam.read();
getFace();
//Changes faceX & faceY to the coordinates of the center of the face after each loop of the draw() method
for (int i = 0; i < faces.length; i++) {
faceX = faces[i].x + (faces[i].width / 2);
faceY = faces[i].y + (faces[i].height / 2);
}
}
void getFace() {
opencv = new OpenCV(this, cam);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
faces = opencv.detect();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment