public void TestFaceStart(string selectedFaceStr) { int selectedFace = -1; // get index try { selectedFace = int.Parse(selectedFaceStr.Split('_').Last()); } catch (Exception) { } // get info TFaces = new QZTestFaces(); try { TFaces.FaceId = QZFaceArr[selectedFace].Id; TFaces.FaceName = QZFaceArr[selectedFace].Name; } catch (Exception) { TFaces.FaceId = -1; TFaces.FaceName = ""; } TFaces.Faces = new List <Image <Gray, byte> >(); TFaces.FaceIds = new List <int>(); // load images string dir = System.IO.Path.GetFullPath($@"../../Faces/"); string[] fileEntries = Directory.GetFiles(dir); foreach (string fileName in fileEntries) { string file = Path.GetFileNameWithoutExtension(fileName); if (((TFaces.FaceId >= 0) && file.StartsWith(TFaces.FaceName)) || (TFaces.FaceId < 0)) { string[] faceParts = file.Split('_'); string faceName = faceParts[0]; int faceId = Convert.ToInt32(faceParts[1]); TFaces.Faces.Add(new Image <Gray, byte>(fileName)); TFaces.FaceIds.Add(faceId); } } // train faces //TFaces.FaceRecognition = new EigenFaceRecognizer(80, double.PositiveInfinity); //TFaces.FaceRecognition = new EigenFaceRecognizer(0, 1.0); TFaces.FaceRecognition = new LBPHFaceRecognizer(); //TFaces.FaceRecognition = new FisherFaceRecognizer(); TFaces.FaceRecognition.Train(TFaces.Faces.ToArray(), TFaces.FaceIds.ToArray()); // open formwebcam FormWebCamOpen(); // test faces Mode = EnMode.TFStart; FrmMain.ButtonBackColor(); }