Skip to content
Olya Andreeva edited this page Mar 14, 2014 · 11 revisions

Description

The program implements the face recognition algorithm Eigenfaces. Its goal is to recognize the person in an image, based on the provided training data. In other words, it matches a given face with one of the known faces.

Usage

In order to provide the images to the program, one should follow the structure:

  • each image should be in PGM format of the same resolution
  • each face has a separate folder named s*, where * is an identifier of the face from 1 to the number of faces
  • each face's images are in its folder, numbered from 1 to the number of samples

An example of such structure can be seen in the program's faces folder.

The next step is to specify the configuration in the config.cpp file, for example:

const int Faces = 40; // Number of faces
const int Samples = 7; // Number of samples per face
const int Width = 92; // Width of each image
const int Height = 112; // Height of each image
const int Eigenfaces = 28; // Number of eigenfaces taken in the algorithm
const std::string DataPath = "faces/"; // Path to the folder with data
const int N = Faces; // Total number of images
const int M = Width*Height; // Resolution
const std::string SampleName = "10"; // Name of the file to classify
const int MaxValue = 255; // Maximum pixel value of the images (see PGM format specification)

With this configuration, the program will train itself on 407 photos located in the faces folder, expecting each photo to have 92112 pixels. Then it will classify photos named 10.pgm in each subfolder of the faces folder, using 28 eigenfaces. MaxValue is used in the output of images generated by a program.

The number of eigenfaces should be chosen heuristically. The followings are the graphs of recognition rates using the default training database:

Recognition rate at different number of faces Recognition rate at different number of samples

To compile the program use the following command:

g++ main.cpp eigen.cpp matrix.cpp config.cpp -o eigenface.out

and to run it:

./eigenface.out

Interpret the output

The output of the program for the previously discussed configuration is:

1. 1
2. 2
3. 3
4. 4
5. 40
6. 6
7. 7
8. 8
9. 9
10. 4
11. 11
12. 12
13. 13
14. 28
15. 15
16. 16
17. 17
18. 18
19. 19
20. 20
21. 21
22. 22
23. 38
24. 24
25. 25
26. 26
27. 27
28. 28
29. 29
30. 30
31. 31
32. 32
33. 33
34. 34
35. 40
36. 36
37. 37
38. 38
39. 22
40. 5
0.825

where, for example, the 1st row can be read as: "The image named 10.pgm in the faces/s1/ folder is classified to be a photo of a person number 1."

The last row contains recognition rate.

Recognize an image

The program can accept as an argument a path to the image that needs to be recognized. For example:

./eigenface.out faces/s2/8.pgm

Then the recognition procedure is run only once, for this specific image. The output in this case is:

2

Additional output

The program also generates additional output that may be interesting to the user. It is located in the output folder.

  • eigenfaces folder contains images given by the eigenvectros of the covariance matrix. They form a basis for the set of faces.
  • normalized folder contains images from the training data with mean image subtracted.
  • meanimage.pgm is the mean image of the training data.

Clone this wiki locally