我使用Emgu.cv进行人脸识别应用。它将图像存储在数据库中,并在识别后告知图像的名称。我的问题是,它没有告诉未知的人,但它自动匹配数据库中最相关的面,并告诉错误的名称。
我想展示"未知"不明人士的字符串。我使用了以下代码:
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;
}
答案 0 :(得分:0)
EigenObjectRecognizer返回String.Empty
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));
将此添加到您的识别表单
希望它有所帮助