如何使用EigenObjectRecognizer阈值

时间:2014-06-22 13:35:45

标签: c# opencv face-recognition emgucv

我尝试编写面部识别程序代码并需要社区的帮助。下面发布的代码编译时没有错误,如果我设置的阈值为0,则识别器工作,如果我设置阈值> 0显示Unknown Face肯定。
我正在为一个人使用4个训练图像。
面对数据库:
人物:
- PersonA1,PersonA2,PersonA3,PersonA4
PersonB:
- PersonB1,PersonB2,PersonB3,PersonB4
场景示例:
如果检测到新人(数据库中没有人)被称为 PersonC ,则程序始终在PersonA或PersonB之间显示来自数据库的名称。

如果数据库中没有面,如何将新检测到的面/ PersonC显示为Unknown Face。我知道哪里出错了?提前谢谢。

我使用emgu cv 2.2.1.1150和c#2010 express
表示 imgRecognizer初始化:

private void AttendanceForm_Load(object sender, EventArgs e)
{
    dbFA = new FRAttendance_DBDataContext();
    timer.Start();
    face = new HaarCascade("haarcascade_frontalface_alt_tree.xml");
    Scanner = new Capture();
    Scanner.QueryFrame();
    Application.Idle += new EventHandler(StartCamera);
    try
    {
    LoadData();
    ImageToList();
    MCvTermCriteria termCrit = new MCvTermCriteria(rowCount, 0.001);
    imgRecognizer = new EigenObjectRecognizer(trainingImages.ToArray(), personsLabel.ToArray(), 1000, ref termCrit);
    }
    catch (Exception err)
    {
        MessageBox.Show(err.ToString());
    }
}

识别器功能:

private void btnScan_Click(object sender, EventArgs e)
{
    if (trainingImages.ToArray() != null)
    {
        try
        {
            faceImgLabel = imgRecognizer.Recognize(result);
            if (faceImgLabel.Trim().Equals(""))
            {
                txtHSID.Text = "Unknown";
                txtHSName.Text = "Unknown";
                MessageBox.Show("Unknown Face", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                logMeIn(faceImgLabel);
            }
        }
        catch(Exception errScan)
        {
            MessageBox.Show(errScan.ToString());
            MessageBox.Show("Wait until face detected", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
    else
        MessageBox.Show("No image in collection list", " Information ", MessageBoxButtons.OK, MessageBoxIcon.Information);
        imgScan.Image = result;
}

0 个答案:

没有答案