Face detection with OpenCV
One of the greatest features of OpenCV is that it allows you to do face detection . In this recipe, we'll take a look at how you can do this with a minimum amount of code.
How to do it...
You need to start by importing the OpenCV library, just like you did in previous OpenCV recipes. You also need to import the java.awt.Rectangle
class, because the face detection algorithm returns rectangle objects. You'll need to type this line yourself, since this is not available from a menu. Inside the setup()
function, we'll configure OpenCV and use the cascade()
method to configure how face tracking works.
import hypermedia.video.*; import java.awt.Rectangle; OpenCV opencv; void setup() { size( 640, 480 ); opencv = new OpenCV( this ); opencv.capture( 320, 240 ); opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); }
In the draw()
function, we'll read a new frame from the webcam, flip it, convert it to a grayscale image, and display it on the screen. The detect()
method...