I've tried to code a face recognition program and need some help from the community. The code posted below compiled with no error and the recognizer working if the threshold that i set is 0, if i set the threshold > 0 its display Unknown Face definitely.
I am using 4 training image for a person.
Face in Database :
PersonA:
- PersonA1, PersonA2, PersonA3, PersonA4
PersonB:
- PersonB1, PersonB2, PersonB3, PersonB4
Scenario Example:
If new person (none in database) face detected lets called PersonC, but the program always display name from database between PersonA or PersonB.
How to display new detected face / PersonC as Unknown Face if there are no face in database. Any idea on where have i gone wrong? Thanks in advance.
I'm using emgu cv 2.2.1.1150 with c# 2010 express
imgRecognizer Initialization:
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());
}
}
Recognizer Function :
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;
}