Face Tracking Using OpenCV

In Computational Media, ITP

For this week, we needed to create a sketch using tracking within a video capture. At first I was going to track an item base on a color difference threshold, but once I started playing with the opencv library, it was too much fun to do anything else.


 

// code

// Download here

//Sketch created with a lot of help from the LiveCamTest example of the OpenCV Library

import gab.opencv.*;
import processing.video.*;
import java.awt.*;

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);

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();
}

Submit a comment