23.10.2014 Views

Exercise 4. The Eigenfaces method training 1. Aim: acquire skills ...

Exercise 4. The Eigenfaces method training 1. Aim: acquire skills ...

Exercise 4. The Eigenfaces method training 1. Aim: acquire skills ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Exercise</strong> <strong>4.</strong> <strong>The</strong> <strong>Eigenfaces</strong> <strong>method</strong> <strong>training</strong><br />

<strong>1.</strong> <strong>Aim</strong>: <strong>acquire</strong> <strong>skills</strong> concerning PCA <strong>training</strong> (creating of covariance matrix,<br />

calculating its eigenvalues and eigenvectors using OpenCV library, acquiring<br />

eigenfaces).<br />

2. Function to be modified: Train<strong>Eigenfaces</strong> in Lab component. <strong>The</strong> following<br />

arguments are passed to the function:<br />

• pImgs – normalised images from the <strong>training</strong> set.<br />

• nImgCount and nImgSize – number of images and their size (number of<br />

pixels).<br />

• pfEigenVectors – a two dimensional array, in which the eigenvectors<br />

should be saved (they should be orthonormal and sorted in descending<br />

order by the corresponding eigenvalues). <strong>The</strong> memory is allocated for<br />

nEigenCount eigenvectors (each has length of nImgSize elements).<br />

• pfEigenValues – an array to which the eigenvalues sorted in the descending<br />

order should be saved. <strong>The</strong> memory is allocated for nEigenCount values.<br />

• pEF – an array similar to pfEigenVectors, but its elements have BYTE<br />

type. <strong>The</strong> eigenvectors should be written not in orthonormal form, but their<br />

elements should be scaled to the 0-255 value range (so that they may be<br />

saved as images).<br />

• nEigenCount – number of eigenvectors which should be calculated.<br />

3. <strong>The</strong> testing consists of two stages:<br />

• PCA <strong>training</strong> is performed by the TrainEF.sf script. <strong>The</strong> <strong>training</strong> set is<br />

specified by image directory and list. <strong>The</strong> MaxEigenCount variable is the<br />

number of eigenvectors to be calculated (<strong>training</strong> is performed by the<br />

Train<strong>Eigenfaces</strong> function). It is possible to set less dimensions of the face<br />

space (utilise less eigenvectors for feature extraction) by the CutEigen<br />

function – the dimensionality is set to EigenCount dimensions (it cannot be<br />

larger than MaxEigenCount).<br />

Attention: If the <strong>training</strong> is not performed correctly, the feature extraction<br />

may result in application crash (it is not checked whether the eigenvectors<br />

have sensible values). It is possible to overwrite the data files (acltw.dat<br />

and aclww.dat) with their original versions. <strong>The</strong>y are located in<br />

c:\RT\install\data (the original are in lab5.zip).<br />

• Tests of recognition effectiveness. When the <strong>training</strong> has been performed, a<br />

recognition test may be performed (in the same way as in previous<br />

exercises – using the recognition_test.sf script).<br />

<strong>4.</strong> Tasks:<br />

• calculate the average face and subtract it from every image in the <strong>training</strong><br />

set.<br />

• calculate the covariance matrix of the <strong>training</strong> set.<br />

• find the eigenvalues and eigenvectors of the covariance matrix. It is<br />

recommended to use the cvmEigenVV function from OpenCV library. <strong>The</strong><br />

eigenvectors and eigenvalues calculated by this function are already sorted.


• scale the calculated eigenvectors to the pixel value range and save them to<br />

pEF array. When the <strong>training</strong> is finished, the images from the array are<br />

saved automatically to c:\RT\test\eigenfaces\Eigen. <strong>The</strong> conclusions drawn<br />

from these images should be listed in the report.<br />

• perform the recognition tests for various numbers of dimensions of the face<br />

space. It is necessary to perform the <strong>training</strong> once (e.g. for 500 dimensions)<br />

and then set the dimensionality using the CutEigen function in the<br />

TrainEF.sf script. An optimal number of dimensions should be found.<br />

Perform the <strong>training</strong> for the FeretB database and the recognition tests for<br />

the FeretA database for 10, 20, ..., 200 dimensions. Draw the conclusions.<br />

5. Remarks concerning OpenCV:<br />

• there is a CvMat object which represents a matrix. It must be created using<br />

the cvCreateMat function (it returns a pointer to the new object) and<br />

deleted using the cvReleaseMat function. It is recommended to use cvmSet<br />

and cvmGet functions to access the matrix data.<br />

• the calculations should be performed for float data type (CV_MAT32F<br />

matrix type).<br />

• the precision coefficient eps should be set to 10 -3 .<br />

• some examples are presented in Lab.cpp.<br />

• more details can be found in the documentation (chapter 23, opencv.pdf<br />

file).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!