February 2010
S M T W T F S
« Dec    
 123456
78910111213
14151617181920
21222324252627
28  

Face Detection Library for Processing (PC)

This is the main project page for the Face Detection Library for Processing.

Information
The Face Detection Library adopts the Intel OpenCV library to provide a more intuitive feature for the Processing users. It makes use of the Haar classifier feature detection and extract human face like regions and passes them back to the Processing program as an array of rectangle information.

Tested environments
The library runs only on Windows (PC). It has been developed and tested under Windows XP SP2. The latest version is built using the Processing 1.0.1 and JVM 1.5 compatibility. The Java part is developed in Eclipse 3.4.1 with the Java Development Kit 1.6.0. The DLL is built using the Microsoft Visual C++ 6.0, targeting X86 and Win32 machines.

Dependencies
The library depends on the OpenCV 1.0. The latest release from OpenCV 1.1 pre 1 does not work. I do not distribute the OpenCV libraries in this version before clearing the licensing restriction. The following OpenCV 1.0 files are essential:

  • cxcore100.dll
  • cv100.dll
  • libguide40.dll

If you do not intend to install OpenCV in your computer, you still need to copy the above DLLs to the Processing root folder.

The configuration XML files in the data folder may have their individual use and distribution concerns. Please refer to them before use.

I did the testing using JMyron as the capture input. The standard use of Quicktime capture is unstable in my testing environment. I have not tested with the Java Media Framework.

Download
Latest one for Processing 1.0.1 – 03 Jan 2008
Last one – 20 Apr, 2008.

Installation
Download and unzip the pFaceDetect folder. Copy only the pFaceDetect folder with only the library folder into the libraries folder of the Processing software. The source files (src folder) are for your reference. You can modify the detection parameters and re-compile for your use. The data folder contains the sample trained classifier files from the OpenCV distribution for actual face recognition. You can add one of them into your sketch’s data folder for use. The reference folder is the Javadoc help material.

Coding – import the library

import pFaceDetect.*;

Coding – define the object instance

PFaceDetect face;

Coding – initialize the object instance

face = new PFaceDetect(this,width,height,
  "haarcascade_frontalface_default.xml");

The first parameter is the current PApplet reference. The 2nd and 3rd parameters are the capture width and capture height. Note that you can use different face detection width and height different from your JMyron ones. In this case, you need to re-calculate the scaling factor when you display the detected rectangles. The last parameter is the file name of the cascade classifier file in your data folder.

Coding – find the faces

PFaceDetect.findFaces(PImage);

The only parameter is a PImage object which contains the latest video capture frame.

Coding – obtain the result

int [] [4] PFaceDetect.getFaces();

The function returns a two-dimensional array that contains all the faces detected. The length of the first dimension is the total number of faces detected. The second dimension is interpreted as,

int [] [0] – top left corner of the face
int [] [1] – bottom right corner of the face
int [] [2] – width of the face
int [] [3] – height of the face

The overall operation is synchronized with the draw() function. No other threads have been implemented.

Example code

import pFaceDetect.*;
import JMyron.*;

PFaceDetect face;
JMyron m;
PImage img;

void setup() {
  size(320,240);
  m = new JMyron();
  m.start(width,height);
  m.findGlobs(0);
  face = new PFaceDetect(this,width,height,
  "haarcascade_frontalface_default.xml");
  frameRate(15);
  img = createImage(width,height,ARGB);
  rectMode(CORNER);
  noFill();
  stroke(255,0,0);
  smooth();
}

void draw() {
  background(0);
  m.update();
  arraycopy(m.cameraImage(),img.pixels);
  img.updatePixels();
  face.findFaces(img);
  image(img,0,0);
  drawFace();
}

void drawFace() {
  int [][] res = face.getFaces();
  if (res.length>0) {
    for (int i=0;i<res.length;i++) {
      int x = res[i][0];
      int y = res[i][1];
      int w = res[i][2];
      int h = res[i][3];
      rect(x,y,w,h);
    }
  }
}

void stop() {
  m.stop();
  super.stop();
}