Eigenfaces in OpenCV using C++

786 views Asked by At

I have written a code to create eigenfaces. I have taken 3 images of different people as input. I have calculated the eigenvectors and eigenvalues. Since only 3 images are taken, I select all the three eigenvectors, each of size 36000x1, as the principal components. When I reshape the eigenvectors to see the image, I get eigenface for only one person. The other images are almost completely blank.

I am extracting each eigenvector from covevec(matrix of eigenvectors of covariance matrix)

col1=covevec.col(0);
col2=covevec.col(1);
col3=covevec.col(2);

I reshape them as follows:

if (!col1.isContinuous() && !col2.isContinuous() && !col3.isContinuous())
{
    col1=col1.clone();
    col2=col2.clone();
    col3=col3.clone();
}
Mat final1,final2,final3;
final1=col1.reshape(0,200);
final2=col2.reshape(0,200);
final3=col3.reshape(0,200);

This how final2 looks like: Output image final2

And the other two look like this:Output image final1

What am I doing wrong?

1

There are 1 answers

0
GPPK On BEST ANSWER

Your code looks fine, so what is wrong?

DataDataData, it's so crucial when performing computer vision tasks like this. To give yourself an advantage use a readily avaliable dataset with corresponding test data - This would work

Also, as berak says normalising the images will help. In Turk & Pentland (Which if you haven't read you should) they state:

Step 6.3: compute the M best eigenvectors of AAT : ui = Avi

(important: normalize ui such that ||ui|| = 1)

This will mean that all your training data will be of the same vein and give your algorithm much better chance of success