Hardware Reference
In-Depth Information
Face Detection Using a Webcam
Now that you've got a basic understand-
ing of how optical detection works from
the color-tracking project, it's time to try
some simple pattern detection. In this
project, you'll use OpenCV's facial-detec-
tion methods to look for faces in a camera
image.
MATERIALS
» Personal computer with uSb or FireWire port
» uSb or FireWire webcam
» Faces
Frontal face view (four variations)
Profile face view
Full-body view
Lower-body view
Upper-body view
OpenCV's pattern detection uses pattern description files
called cascades to describe the characteristics of a partic-
ular patern. A cascade describes the subregions of a given
pattern, including their relative sizes, shapes, and contrast
ratios. The patterns are designed to be general enough to
allow for some variation, but specific enough to tell it from
other patterns. The Processing OpenCV library comes with
patterns for the following human features:
The sketch attempts basic facial recognition; see if you
can fool it.
Before the setup() , set up the
global variables as usual. These are
almost identical to the last project,
but you also need the Java Rectangle
object. This is because the OpenCV
detection method returns an array of
Rectangles that it thinks contain faces.
8
/*
Face detection using openCV
Context: Processing
*/
// import the opencv and Rectangle libraries:
import hypermedia.video.*;
import java.awt.Rectangle;
The setup() is similar, but this time,
you're going to have OpenCV look for
detection pattern using the library's
cascade() method. The available
patterns are described on the Process-
ing OpenCV site at http://ubaa.net/
shared/processing/opencv/opencv_
cascade.html .
OpenCV opencv; // new instance of the openCV library
void setup() {
// initialize the window:
size( 320,240 );
// initialize opencv:
opencv = new OpenCV( this );
opencv.capture( width, height );
// choose a detection description to use:
opencv.cascade( OpenCV.CASCADE_FRONTALFACE_DEFAULT );
// draw smooth edges:
smooth();
// set ellipses to draw from the upper left corner:
ellipseMode(CORNER);
}
Finally, the setup() sets the drawing
conditions for ellipses, so you can draw
circles over the faces.
Search WWH ::




Custom Search