Can some help me with this issue, have a facial recognition app but when my camera records an image of a person who is not in the database yet, the application still displays the name of a person I have added to the database... some code below i think the issue might be
- if (isTrained) {
- Image < Gray, Byte > grayFaceResult = resultImage.Convert < Gray, Byte > ().Resize(200, 200, Inter.Cubic);
- CvInvoke.EqualizeHist(grayFaceResult, grayFaceResult);
- var result = recognizer.Predict(grayFaceResult);
- pictureBox1.Image = grayFaceResult.Bitmap;
- pictureBox2.Image = TrainedFaces[result.Label].Bitmap;
- Debug.WriteLine(result.Label + ". " + result.Distance);
-
- if (result.Label != -1 && result.Distance < 2000) {
- CvInvoke.PutText(currentFrame, PersonsNames[result.Label], new Point(face.X - 2, face.Y - 2),
- FontFace.HersheyComplex, 1.0, new Bgr(Color.Orange).MCvScalar);
- CvInvoke.Rectangle(currentFrame, face, new Bgr(Color.Green).MCvScalar, 2);
- }
-
- else {
- CvInvoke.PutText(currentFrame, "Unknown", new Point(face.X - 2, face.Y - 2),
- FontFace.HersheyComplex, 1.0, new Bgr(Color.Orange).MCvScalar);
- CvInvoke.Rectangle(currentFrame, face, new Bgr(Color.Red).MCvScalar, 2);
-
- }
- }
- private bool TrainImagesFromDir() {
- int ImagesCount = 0;
- double Threshold = 2000;
- TrainedFaces.Clear();
- PersonsLabes.Clear();
- PersonsNames.Clear();
- try {
- string path = Directory.GetCurrentDirectory() + @ "\TrainedImages";
- string[] files = Directory.GetFiles(path, "*.jpg", SearchOption.AllDirectories);
-
- foreach(var file in files) {
- Image < Gray, byte > trainedImage = new Image < Gray, byte > (file).Resize(200, 200, Inter.Cubic);
- CvInvoke.EqualizeHist(trainedImage, trainedImage);
- TrainedFaces.Add(trainedImage);
- PersonsLabes.Add(ImagesCount);
- string name = file.Split('\\').Last().Split('_')[0];
- PersonsNames.Add(name);
- ImagesCount++;
- Debug.WriteLine(ImagesCount + ". " + name);
-
- }
-
- if (TrainedFaces.Count() > 0) {
-
- recognizer = new EigenFaceRecognizer(ImagesCount, Threshold);
- recognizer.Train(TrainedFaces.ToArray(), PersonsLabes.ToArray());
-
- isTrained = true;
-
-
- return true;
- } else {
- isTrained = false;
- return false;
- }
- } catch (Exception ex) {
- isTrained = false;
- MessageBox.Show("Error in Train Images: " + ex.Message);
- return false;
- }