Reputation: 59
By referring to the previous post, the method used for classification was Euclidean Distance with Nearest Neighbor. However, the result obtained is not accurate as both known dataset and unknown dataset are giving similarity 99%. Even with Mahalanobis distance also gives similar result.
Is there any other method for face recognition classification? Could you provide me some examples/formulae?
float d_i = projectedTestFace[i] - projectedTrainFaceMat->data.fl[iTrain*nEigens + i];
distSq += d_i*d_i; // Euclidean distance
Upvotes: 0
Views: 460
Reputation: 59
// Compare two images by getting the L2 error (square-root of sum of squared error).
double getSimilarity(const Mat A, const Mat B)
{
if (A.rows > 0 && A.rows == B.rows && A.cols > 0 && A.cols == B.cols) {
// Calculate the L2 relative error between the 2 images.
double errorL2 = norm(A, B, CV_L2);
// Convert to a reasonable scale, since L2 error is summed across all pixels of the image.
double similarity = errorL2 / (double)(A.rows * A.cols);
return similarity;
}
else {
//cout << "WARNING: Images have a different size in 'getSimilarity()'." << endl;
return 100000000.0; // Return a bad value
}
}
I wonder why i always get return 100000000. Does it means that the preprocessed and reconstructed face have difference size? That's why it skips the L2 distance comparison?
Below are part of my coding:
Mat j =projectedTestFace[i];
Mat k =projectedTrainFaceMat>data.fl[iTrain*nEigens + i];
similarity=getSimilarity(j,k);
without the else statement, i get similarity=-nan result, wondering what are -nan and -inf stand for.
Upvotes: 0
Reputation: 39796
imho, if you get bad results, blame your input, not the distance formula
without any further preprocessing(alignment,cropping,equalization), even a plain L2 norm over the pixels gives better results, than eigenfaces. (sad truth here)
since 2.4.2, opencv has face-recognition out of-the-box. (also with alternative fisher and lbph features)
you probably should use that, instead of rolling your own (and please use the c++ api, not the arcane c one).
if you do want to stick with eigenfaces, you still could try the L2 distance beween a 'reconstructed' (from the eigenvecs) image and the test image as a confidence measure, as done here (by shervin, again)
Upvotes: 1