final code | Processing

Below is a copy of my final program code.


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

Capture video;
OpenCV opencv;

//PImages to store captured faces
PImage face0 = createImage(0, 0, RGB);
PImage face1 = createImage(0, 0, RGB);
PImage face2 = createImage(0, 0, RGB);
PImage face3 = createImage(0, 0, RGB);
void setup() {
size(640, 480);
video = new Capture(this, 640, 480, 20);
opencv = new OpenCV(this, 640, 480);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
frameRate(6);
video.start();
smooth();
}

void draw() {
//need to scale up to make the image bigger at some point
scale(1);

//display video feed
opencv.loadImage(video);
image(video, 0, 0 );
filter(GRAY);

//array to store the faces
Rectangle[] faces = opencv.detect();
println(faces.length);
if (faces.length >= 1) {
face0 = get(faces[0].x, faces[0].y, faces[0].width, faces[0].height);
face0.filter(BLUR, 6);
image(face0, faces[0].x, faces[0].y);
if (faces.length >= 2) {
face1 = get(faces[1].x, faces[1].y, faces[1].width, faces[1].height);
face1.filter(BLUR, 6);
image(face1, faces[1].x, faces[1].y);
if (faces.length >= 3) {
face2 = get(faces[2].x, faces[2].y, faces[2].width, faces[2].height);
face2.filter(BLUR, 6);
image(face2, faces[2].x, faces[2].y);
if (faces.length >= 4) {
face3 = get(faces[3].x, faces[3].y, faces[3].width, faces[3].height);
face3.filter(BLUR, 6);
image(face3, faces[3].x, faces[3].y);
}
}
}
}
} // close draw
void captureEvent(Capture c) {
c.read();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s