public bool TrainRecognizer(int recognizerIndex) { var allFaces = new List <ImageWithLabelModel>(); allFaces = _parameters.UseExplorer ? _localStorageService.GetAllImagesWithLabels() : _databaseService.GetAllImagesWithLabels(); var count = allFaces.Count(); if (count <= 0) { return(true); } var faceImages = new Image <Gray, byte> [count]; var faceLabels = new int[count]; for (var i = 0; i < count; i++) { var stream = new MemoryStream(); stream.Write(allFaces[i].Data, 0, allFaces[i].Data.Length); var faceImage = new Image <Gray, byte>(new Bitmap(stream)); faceImages[i] = faceImage.Resize(100, 100, Inter.Cubic); faceLabels[i] = allFaces[i].PersonId; } FaceRecognizer.Train(faceImages, faceLabels); switch (recognizerIndex) { case 0: FaceRecognizer.Write( _parameters.UseExplorer ? RecognizerConfig.EigenLocalConfigurationPath : RecognizerConfig.EigenDatabaseConfigurationPath); break; case 1: FaceRecognizer.Write( _parameters.UseExplorer ? RecognizerConfig.FisherLocalConfigurationPath : RecognizerConfig.FisherDatabaseConfigurationPath); break; case 2: FaceRecognizer.Write( _parameters.UseExplorer ? RecognizerConfig.LbphLocalConfigurationPath : RecognizerConfig.LbphDatabaseConfigurationPath); break; } return(true); }