This chapter does not appear in the book.
This chapter explains how a face can be tracked via webcam. As with earlier examples, I'll grab frames from the webcam, and draw them rapidly onto a panel. At the same time, a detector analyzes the frames to find a face and highlight it in the panel. The application, called FaceTracker, is shown in action in the pictures at the top of the page. The tracker draws a yellow rectangle around the face, and red crosshairs entered inside the rectangle.
The detection code is fast when there's a face present in the image (around 20ms), but may take substantially longer to decide there's no face (as much as 100ms). Two important aspects of the coding are finding ways to speed up the detection, and making sure that lengthy detection processing don't slow down the rest of the program (in particular, the rapid rendering of successive images onto the panel).
The rectangle coordinates returned by the tracker could be used to guide the DreamCheeky Missile Launcher described back in Chapter 4, although I won't be repeating that code here. Instead, the aim of the next chapter is to extend the processing to recognize the tracked face. The distinction between face detection and recognition is that recognition returns a name for the face. The control software for the launcher could then decide whether the person is a friend or for before firing a missile.
Detection is carried out by a Haar classifier, pre-trained to find facial features (when viewed front-on). The classifier's training requires a great deal of time, but thankfully I can skip that stage because I'm using a face classifier that's already part of the OpenCV computer vision library. OpenCV, and its Java interface (called JavaCV), were introduced back in Chapter 3.