public int RecognizeUser(Image <Gray, byte> userImage) { /* Stream stream = new MemoryStream(); * stream.Write(userImage, 0, userImage.Length); * var faceImage = new Image<Gray, byte>(new Bitmap(stream));*/ try { _faceRecognizer.Load(_recognizerFilePath); var result = _faceRecognizer.Predict(userImage.Resize(200, 200, Inter.Cubic, false)); System.Diagnostics.Debug.WriteLine(result.Label + " - " + result.Distance); return(result.Label);//result.Distance < 100 ? result.Label : -1; } catch (Exception ex) { if (ex.Message != "OpenCV: Unsupported file storage format") { MessageBox.Show("Mensagem de erro desconhecida:" + ex.Message); } else { MessageBox.Show("A imagem fornecida não possui um formato válido."); } } return(-1); }
/// <summary> /// Recognise a Grayscale Image using the trained Eigen Recogniser /// </summary> /// <param name="Input_image"></param> /// <returns></returns> public string Recognise(Image <Gray, byte> Input_image, int Eigen_Thresh = -1) { if (_IsTrained) { FaceRecognizer.PredictionResult ER = recognizer.Predict(Input_image); if (ER.Label == -1) { Eigen_label = "Unknown"; Eigen_Distance = 0; return(Eigen_label); } else { Eigen_label = Names_List[ER.Label]; Eigen_Distance = (float)ER.Distance; if (Eigen_Thresh > -1) { Eigen_threshold = Eigen_Thresh; } //Only use the post threshold rule if we are using an Eigen Recognizer //since Fisher and LBHP threshold set during the constructor will work correctly switch (Recognizer_Type) { case ("EMGU.CV.EigenFaceRecognizer"): if (Eigen_Distance > Eigen_threshold) { return(Eigen_label); } else { return("Unknown"); } case ("EMGU.CV.LBPHFaceRecognizer"): case ("EMGU.CV.FisherFaceRecognizer"): default: return(Eigen_label); //the threshold set in training controls unknowns } } } else { return(""); } }
/// <summary> /// Recognise a Grayscale Image using the trained Eigen Recogniser /// </summary> /// <param name="Input_image"></param> /// <returns></returns> public string Recognise(Image <Gray, byte> Input_image, int Eigen_Thresh = -1) { if (_IsTrained) { FaceRecognizer.PredictionResult ER = recognizer.Predict(Input_image); if (ER.Label == -1) { Eigen_label = "Unknown"; Eigen_Distance = 0; return(Eigen_label); } else { Eigen_label = Names_List[ER.Label]; Eigen_Distance = (float)ER.Distance; if (Eigen_Thresh > -1) { Eigen_threshold = Eigen_Thresh; } //Only use the post threshold rule if we are using an Eigen Recognizer //since Fisher and LBHP threshold set during the constructor will work correctly if (Eigen_Distance > Eigen_threshold) { return(Eigen_label); } else { return("Unknown"); } } } else { return(""); } }