 |
| |
|
Seeing With OpenCV, Part 3: Follow that Face!
(Continued)
|
|
|
|
This article originally appeared in
SERVO Magazine, March 2007.
Reprinted by permission of T & L Publications, Inc.
|
| |
Helper Functions
In addition to the main program, TrackFaces.c also contains helper functions for initialization and cleanup - initAll() and exitProgram(). These are shown in
Figure 4.
At line 21 in initAll(), the call to the Camshift wrapper's createTracker() function pre-allocates the wrapper's internal data structures. It's not necessary to pre-allocate the tracking data, but doing so speeds the transition from face detection to tracking. The next two statements (lines 24-25) set the parameters smin and vmin. The best values to use for these depends on your setup, so it's a good idea to select them ahead of time, using the camshiftdemo program, as described above.
|
|
|
|
|
Figure 4. The helper functions initAll() and exitProgram() handle program initialization and cleanup
|
|
 |
|
Figure 5
shows the listing for captureVideoFrame(). At line 11, a call to cvFlip() flips the image upside down if the origin field is 0. The reason for doing this is that some webcam drivers, especially on Windows, deliver image pixels starting at the bottom, rather than at the top, of the image. The origin field indicates which row order the IplImage uses. Some OpenCV functions will only work correctly when these images are inverted.
|
|
|
|
|
Figure 5. The helper function captureVideoFrame(). At line 11, the call to cvFlip() flips the image upside down if the origin field is 0.
|
|
 |
|
Finally,
Figure 6
contains the detectFace() function. Although this code should be familiar from last month's article, one point worth noting is that the min_neighbors parameter should be set high enough that false face detections are unlikely. (Otherwise, your robot might start tracking the refrigerator magnets!) At line 10, I've set it to 6, which is more restrictive than the default value of 3.
|
|
|
|
|
Figure 6. The detectFace() function. The min_neighbors parameter is set to 6 to reduce the chance of a false detection.
|
|
 |
|
Next...
So far, the faces we've been finding and following have been anonymous. The robot can tell there's a face present, and can follow it, but has no way of knowing who's face it is. The process of linking faces to names is called face recognition. OpenCV contains a complete implementation of a face-recognition method called eigenface.
The remaining two articles in this series explain how to use OpenCV's eigenface implementation for face recognition. In the first of these, I'll explain how the algorithm works and give you code to create a database of people your robot "knows." The article following that takes you through the steps for recognition from live video, and gives you tips to help you get the most out of eigenface.
Be seeing you!
|
 |
|
 |