I was working on Face Recognition and when i run the code it stops execution at the point where EigenObjectRecognizer is initialized and exits the program with out any error.Have any one else faced the same problem ever before?If you need additional codes i can post more. I have seen my code working until the point where the recognizer trained with data in the training set
EigenObjectRecognizer recognizer = new EigenObjectRecognizer(
trainingImages.ToArray(),
NameLabless.ToArray(),
3000,
ref termCrit);
name = recognizer.Recognize(ExtFaces[faceNo]).ToString();
The code that i have used to load from the training set is
public FaceRecognizer()
{
InitializeComponent();
try
{
ContTrain = ContTrain + 1;
string NameLabelsinfo = File.ReadAllText(Application.StartupPath +
"/TrainedFaces/TrainedNameLables.txt");
string[] NameLabels = NameLabelsinfo.Split('%');
NumNameLabels = Convert.ToInt16(NameLabels[0]);
string IDLabelsinfo = File.ReadAllText(Application.StartupPath +
"/TrainedFaces/TrainedNameLables.txt");
string[] IDLables = IDLabelsinfo.Split('%');
NumIDLabels = Convert.ToInt16(IDLables[0]);
if (NumNameLabels == NumIDLabels)
{
ContTrain = NumNameLabels;
string LoadFaces;
for (int tf = 1; tf < NumNameLabels + 1; tf++)
{
LoadFaces = String.Format("face{0}.bmp", tf);
trainingImages.Add(new Image<Gray, byte>(String.Format("
{0}/TrainedFaces/{1}", Application.StartupPath,
LoadFaces)));
IDLabless.Add(IDLables[tf]);
NameLabless.Add(NameLabels[tf]);
}
}
}
catch (Exception e)
{
MessageBox.Show("Nothing in binary database, please add at least a
face(Simply train the prototype with the Add
Face Button).", "Triained faces load", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
}
And the face recognizer function is as follows
private void RecognizeFaces()
{
Image<Gray, byte> grayframe = GetGrayframe();
MinNeighbors = int.Parse(comboBoxMinNeigh.Text);
WindowsSize = int.Parse(textBoxWinSiz.Text);
ScaleIncreaseRate = Double.Parse(comboBoxScIncRte.Text);
var faces = grayframe.DetectHaarCascade(haar, ScaleIncreaseRate, MinNeighbors,
HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new Size(WindowsSize, WindowsSize))[0];
if (faces.Length > 0)
{
Bitmap ExtractedFace;
ExtFaces = new Image<Gray, byte>[faces.Length];
faceNo = 0;
foreach (var face in faces)
{
t = t + 1;
ExtractedFace = new Bitmap(face.rect.Width, face.rect.Height);
ExtFaces[faceNo] = new Image<Gray, byte>(ExtractedFace);
ExtFaces[faceNo] = ExtFaces[faceNo].Resize(100, 100,
Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
MCvTermCriteria termCrit = new MCvTermCriteria(ContTrain, 0.001);
if (trainingImages.ToArray().Length != 0)
{
EigenObjectRecognizer recognizer = new EigenObjectRecognizer(
trainingImages.ToArray(),
NameLabless.ToArray(),
3000,
ref termCrit);
name = recognizer.Recognize(ExtFaces[faceNo]).ToString();
stringOutput[faceNo] = name;
}
faceNo++;
}
pbExtractedFaces.Image = ExtFaces[0].ToBitmap();
in the 0th (gray) channel with blue
color
t = 0;
if (stringOutput[0] == null)
{
label1.Text = "Unknown";
label9.Text = "";
}
else
{
label1.Text = "Known";
label9.Text = stringOutput[0];
}
}
if (faceNo == 0)
{
MessageBox.Show("No face detected");
}
else
{
btnNextRec.Enabled = true;
btnPreviousRec.Enabled = true;
}
}
When this face recognizer method is called as an event it works until the point where EigenObjectRecognizer is trained and then it stops working(Exit running) and the program stops running at all.
I will look forward for your response,Thanks Sisay