Skip to content

Instantly share code, notes, and snippets.

@slambert
Created April 1, 2017 23:08
Show Gist options
  • Save slambert/a0df4064a042c137417143d02783d42c to your computer and use it in GitHub Desktop.
Save slambert/a0df4064a042c137417143d02783d42c to your computer and use it in GitHub Desktop.
replaces your face with an image
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
PImage b;
Capture video;
OpenCV opencv;
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);
b = loadImage("Happy_smiley_face.png"); // replace with your mask image
video.start();
}
void draw() {
scale(2);
opencv.loadImage(video);
image(video, 0, 0 ); // show the camera on the screen
noFill();
stroke(0, 255, 0);
strokeWeight(3);
Rectangle[] faces = opencv.detect();
println(faces.length);
for (int i = 0; i < faces.length; i++) {
println("face loc: " + faces[i].x + "," + faces[i].y); // where the face?
//point(faces[i].x, faces[i].y); // draw a point
//point(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
image(b, faces[i].x, faces[i].y, faces[i].width, faces[i].height); //replace with image "b"
}
}
void captureEvent(Capture c) {
c.read();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment