0

I been experimenting with face recognition using the Fisherfaces algorithm as a model and wanted to see if the same could be applied to non face object. I see my app work as the following:

  1. create a set of images(Mats) of the the object and save them to a directory with co-responding index for the identity of the object.
  2. load the directory content as Mats, sort it in array and pass it to the model for training.
  3. get the eigenvectors and average mats from the model and reconstruct the object with it.
  4. compere the similarity of the reconstructed object to the original one and predict the identity.

here is the code I was going to use for the training (step 2):

//check if the contrib module is available first
bool contribModelStatus = initModule_contrib();
if ( !contribModelStatus )
    exit(1);

//define the model
Ptr<FaceRecognizer> model;
model = Algorithm::create<FaceRecognizer>(recAlgorithmFisherfaces);
//check if the model was loaded properly
if (model.empty())
    exit(1);

//train the model
model->train(objectsArray, labelsArray); 

for the recognition (step 3):

Mat eigenvectors = model->get<Mat>("eigenvectors");
Mat average = model->get<Mat>("mean");

int height = obj.rows;

//define a projection Mat based on the eigenvectors, avarage object and the object we'll like to test
Mat projection = subspaceProject(eigenvectors, average, obj.reshape(1,1));
//reconstruct the projection and reshape it.
Mat reconstructionRow = subspaceReconstruct(eigenvectors, average, projection);
Mat reconstructionMat = reconstructionRow.reshape(1, height);
Mat reconsructedObj = Mat(reconstructionMat.size(), CV_8U);
reconstructionMat.convertTo(reconsructedObj, CV_8U, 1, 0 );

and for the prediction (step 4):

// ... compeare the similarity of the reconstructionMat to the original object and predict
double similarity = getSimilarity(recognizeMat, reconsructedObj);
float obj_treshold = 0.7f;
check if the similarity is larger then the treshold
f (similarity > obj_treshold) {
    identity = model->predict(recognizeMat);
    cout << "Object identity: " << toString(identity) << endl;
} else {
    cout << "unidentified object" << endl;
}

I been getting some errors trying this - I assume that it has to do with the fact that I have not trained a large amount of data, my question is however will this be reliable for objects that are not faces, or does the face recognition algorithms work only with faces, are there different algorithms in opencv that should be used to recognize non face objects.

here is a link to error I'm getting. http://lab.onetwoclick.com/stuff/stackoverflow/opencv_Fisherfaces_Eigenfaces.jpg

  • What type of errors do you mean? The objects aren't recognized? What kind of objects are you trying to recognize? Eigenspace decomposition can work for non-face objects, but accuracy could depend on various factors. – bruvel Oct 03 '13 at 01:18
  • Thanks for the replay! I get an error about the sizes of images being different, I think I know how to solve that. The objects I want to recognize vary. the first experiment I was doing was on cat faces, it seems to work well, but then since the similarity between different cats it isn't as accurate as human faces. –  Oct 03 '13 at 19:07

0 Answers0