我正在使用 Javacv 1.1。已使用约翰·列侬的图像来测试人脸识别,其中包含一个数据库,其中包含 3 张克里斯蒂亚诺·罗纳尔多图像和 3 张约翰·特里图像。为了验证我的程序没有在数据库中找到约翰·列侬,我使用了他的照片。
但是当程序预测谁是图像中的人时,向我显示 Cristiano Ronaldo 是最相似的人。
我需要输入图像和最相似的训练图像之间的距离来检查是否足够相似来告诉我谁是谁,或者如果不够相似则告诉那里的人不认识。
另一个问题: 有什么改进正确匹配的技巧吗?
最佳答案
这是我的解决方案(仅针对 Android 平台测试),假设您使用特征脸:
public boolean verifyPerson (Mat matResized) {
CvArr eigenvectors = faceRecognizer.getMat("eigenvectors");
CvArr averageFaceRow = faceRecognizer.getMat("mean");
IplImage img1D =MatToIplImage(matResized.reshape(1,1),-1, -1);
// Project the input image onto the eigenspace:
CvMat projection = subspaceProject(eigenvectors, averageFaceRow, img1D);
// Generate the reconstructed face back from the eigenspace:
CvMat reconstructionRow = subspaceReconstruct(eigenvectors, averageFaceRow, projection);
CvMat reconstructionMat = new CvMat();
cvReshape(reconstructionRow, reconstructionMat, 1, matResized.height());
Mat reconstructedFace = CvMatToMat(reconstructionMat);
// Calculate the L2 relative error between the 2 images.
double errorL2 = Core.norm(matResized, reconstructedFace, CV_L2);
// Scale the value since L2 is summed across all pixels.
double uncertainty = errorL2 / (double)(matResized.rows() * matResized.cols());
boolean verified;
if (uncertainty < MaxPersonUncertainty) {
verified = true;
}else{
verified = false; // Unknown person.
}
return verified;
}
关于java - 如何在Javacv中获取人脸相等范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35494975/