This chapter does not appear in the book.
This chapter explains how a face can be tracked. 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 40ms), but may take substantially longer to decide there's no face (as much as 200ms). 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 next chapter will 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.