Intermediate: Me Gusta Face Detection

Do you have processing installed?

Do you know about Motherfucking Classes?

If the answer is yes, then you are ready to learn Computer Vision in Processing.


You better be.

Click here now:

Install the Library with the instructions on the landing page.



Install the library before continuing. Problem?

Place your  meGusta.png inside your sketch folder.


Copy, paste, read and run:


//Import the libraries.
//This one is for OpenCV
//This one is for the array of faces detected returned as rectangles.
import java.awt.Rectangle;

//Create a computer vision Object
OpenCV opencv;

//Create a Processing Image object.
PImage meGusta;

void setup() {

//Set a small size unless you have a powerful processor.

//Use the smooth() function
//Trust me, the edges will look much nicer.

//Let’s initialize the openCV object.
opencv = new OpenCV( this );
//Because we already declared the size we use the width and height var
//to set the size of the capture.
opencv.capture( width, height );
//This is what it will look for.
//Check all that can OpenCV can do here:
opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );

//Load your megusta png picture.
//Remember it needs to be inside your folder. Check caps. Problem?
meGusta = loadImage(“MeGusta.png”);

void draw() {

// grab a new frame;
// and convert to gray
opencv.convert( GRAY );

// proceed detection
Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );

// display the image
image( opencv.image(), 0, 0 );

//if there’s a detected face the length will be greater that 0.
if(faces.length >= 1)
//scale the meGusta.png to desired size.
//place image using the first face in the [0] index.



If you want to start playing with the reference:


Flattr this


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s