public Form1()
{
InitializeComponent();
recognizer = new LBPHFaceRecognizer(1, 8, 8, 9, 65);
classifier = new CascadeClassifier(haarcascade);
GPU_classifier = new GpuCascadeClassifier(haarcascade_cuda);
font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_TRIPLEX, 0.5, 0.5);
if (File.Exists(@"traningdata.xml"))
{
recognizer.Load(@"traningdata.xml");
}
else
{
foreach (var file in Directory.GetFiles(Application.StartupPath + @"\Traning Faces\"))
{
try { temp = new Image<Gray, Byte>(file); }
catch { continue; }
temp._EqualizeHist();
var detectedFaces = classifier.DetectMultiScale(temp, 1.1, 15, new Size(24, 24), Size.Empty);
if (detectedFaces.Length == 0)
{
continue;
}
temp.ROI = detectedFaces[0];
temp = temp.Copy();
temp = temp.Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
imagesList.Add(temp);
imagesLabels.Add(Path.GetFileNameWithoutExtension(file));
}
for (int i = 0; i < imagesList.Count; i++)
{
imagesLabels_indices.Add(i);
}
try { recognizer.Train(imagesList.ToArray(), imagesLabels_indices.ToArray()); }
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Environment.Exit(0);
}
}
}