我一直在尝试使用Fisherfaces算法作为模型进行人脸识别,并希望了解是否可以将相同的方法应用于非面部对象。我看到我的应用程序如下工作:
这是我将用于培训的代码(第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);
用于识别(步骤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 );
和预测(步骤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;
}
我在尝试这个时遇到了一些错误 - 我认为这与我没有训练过大量数据的事实有关,但我的问题是这对于非面部的对象是否可靠,或者是人脸识别算法只适用于人脸,opencv中有不同的算法应该用于识别非人脸对象。
这是我收到错误的链接。 http://lab.onetwoclick.com/stuff/stackoverflow/opencv_Fisherfaces_Eigenfaces.jpg