C# 如何为陌生人使用Emgu.cv?
我正在使用Emgu.cv进行人脸识别应用。它将人脸图像存储在数据库中,并在识别后告知图片的名称。我的问题是,它不会告诉未知的人,但它会自动匹配数据库中最相关的人脸,并告诉错误的名字 我想为未知的人显示“未知”字符串。我使用了以下代码:C# 如何为陌生人使用Emgu.cv?,c#,emgucv,face-recognition,C#,Emgucv,Face Recognition,我正在使用Emgu.cv进行人脸识别应用。它将人脸图像存储在数据库中,并在识别后告知图片的名称。我的问题是,它不会告诉未知的人,但它会自动匹配数据库中最相关的人脸,并告诉错误的名字 我想为未知的人显示“未知”字符串。我使用了以下代码: public String Recognize(Image<Gray, Byte> image) { int index; float eigenDistance; String label; FindM
public String Recognize(Image<Gray, Byte> image)
{
int index;
float eigenDistance;
String label;
FindMostSimilarObject(image, out index, out eigenDistance, out label);
return (_eigenDistanceThreshold <= 0 || eigenDistance < _eigenDistanceThreshold ) ? _labels[index] : String.Empty;
}
public EigenObjectRecognizer(Image<Gray, Byte>[] images, String[] labels, double eigenDistanceThreshold, ref MCvTermCriteria termCrit)
{
Debug.Assert(images.Length == labels.Length, "The number of images should equals the number of labels");
Debug.Assert(eigenDistanceThreshold >= 0.0, "Eigen-distance threshold should always >= 0.0");
CalcEigenObjects(images, ref termCrit, out _eigenImages, out _avgImage);
/*
_avgImage.SerializationCompressionRatio = 9;
foreach (Image<Gray, Single> img in _eigenImages)
//Set the compression ration to best compression. The serialized object can therefore save spaces
img.SerializationCompressionRatio = 9;
*/
_eigenValues = Array.ConvertAll<Image<Gray, Byte>, Matrix<float>>(images,
delegate(Image<Gray, Byte> img)
{
return new Matrix<float>(EigenDecomposite(img, _eigenImages, _avgImage));
});
_labels = labels;
_eigenDistanceThreshold = eigenDistanceThreshold;
}
公共字符串识别(图像)
{
整数指数;
浮动特征距离;
字符串标签;
FindMostSimilarObject(图像、外索引、外特征距离、外标签);
返回(_特征距离阈值=0.0,“特征距离阈值应始终>=0.0”);
钙离子对象(图像、参考术语临界值、输出特征图像、输出平均值);
/*
_avgImage.SerializationCompressionRatio=9;
foreach(图像img in_eigenImages)
//将压缩比率设置为最佳压缩。因此,序列化对象可以节省空间
img.SerializationCompressionRatio=9;
*/
_特征值=数组.ConvertAll(图像,
代表(图像img)
{
返回新矩阵(特征分解(img,_特征图像,_平均值));
});
_标签=标签;
_本征距离阈值=本征距离阈值;
}
特征对象识别器返回一个字符串。为空
return (_eigenDistanceThreshold <= 0 || _eigenDistance < _eigenDistanceThreshold ) ? _labels[index] : String.Empty; // <--- this one
将此添加到您的识别表中
希望能有所帮助
ImageFrame.Draw(string.IsNullOrEmpty(name) ? "UNKNOWN" : name, ref font, new Point(f.rect.X - 2, f.rect.Y - 2), new Bgr(Color.Green));