 |
| |
|
Seeing With OpenCV, Part 5: Implementing Eigenface
(Continued)
|
|
|
|
This article originally appeared in
SERVO Magazine, May 2007.
Reprinted by permission of T & L Publications, Inc.
|
| |
Source Code
Figures 2-10 contain the complete source listing for a basic eigenface program. To keep the presentation simple, I've omitted most of the error checking.
The top-level listing
Figure 2
shows the top-level source listing for Eigenface, a program to learn and recognize faces with OpenCV's eigenface methods. At line 4, it includes cvaux.h. Until now, we've only included cv.h and highgui.h. But we'll use two specialized functions for face recognition, cvCalcEigenObjects() and cvEigenDecomposite(), that are defined in cvaux.h.
|
|
|
|
Figure 2. (Click for larger view) The top-level source listing for the Eigenface program.
|
|
The primary variables for Eigenface are defined at lines 8-15. One of the datatypes here, CvMat, is one we haven't used before. This is OpenCV's matrix datatype. A matrix contains a table of data, arranged as rows and columns.
If you only need to hold data temporarily within your program, an ordinary C-style array is usually a little easier to use than CvMat. But the CvMat datatype can be nice when you want to take advantage of OpenCV functions for working with matrix data. The ones we'll use are OpenCV's persistence functions. With these, you can store matrix data with a single line of code. Reading it back into your programs later is just as easy. Here, I've use a C array for two variables (faceImgArr and eigenVectArr), and CvMat for several others.
The main() function simply reads the input string, then calls either the learn() method or the recognize() method.
Figure 3
shows the printUsage() helper function.
|
|
|
|
Advertisement
|
|
|
 |
|
|
|
|
Figure 3. (Click for larger view) The printUsage() helper function.
|
|
CONTINUED
1
2
3
4
5
Next
|
 |
|
 |