private async Task TrainPersonGroupTask() { //#4. API to train the person groups await _faceClient.TrainPersonGroupAsync(personGroupId); FaceAPI.Contract.TrainingStatus trainingStatus = null; while (true) { trainingStatus = await _faceClient.GetPersonGroupTrainingStatusAsync(personGroupId); if (trainingStatus.Status != FaceAPI.Contract.Status.Running) { break; } await Task.Delay(1000); } }
public async Task <Boolean> StartTraining() { _faceClient = new FaceAPI.FaceServiceClient(Properties.Settings.Default.FaceAPIKey, Properties.Settings.Default.FaceAPIHost); await _faceClient.TrainPersonGroupAsync(_groupId); TrainingStatus trainingStatus = null; while (true) { trainingStatus = await _faceClient.GetPersonGroupTrainingStatusAsync(_groupId); if (trainingStatus.Status != Status.Running) { break; } await Task.Delay(1000); } var persons = await _faceClient.ListPersonsAsync(_groupId); return(true); }
private async void FacialRecognitionTraining_Click(object sender, RoutedEventArgs e) { try { TrainingStatus trainingStatus = null; await _faceClient.TrainPersonGroupAsync(_personGroupId); while (true) { trainingStatus = await _faceClient.GetPersonGroupTrainingStatusAsync(_personGroupId); if (trainingStatus.Status != Status.Running) { break; } await Task.Delay(2000); } } catch (Exception ex) { } }
/// <summary> Function which submits a frame to the Emotion API. </summary> /// <param name="frame"> The video frame to submit. </param> /// <returns> A <see cref="Task{LiveCameraResult}"/> representing the asynchronous API call, /// and containing the emotions returned by the API. </returns> private async Task TrainCognitiveServicesAsync() { _faceClient = new FaceAPI.FaceServiceClient(Properties.Settings.Default.FaceAPIKey, Properties.Settings.Default.FaceAPIHost); var pgexists = await _faceClient.GetPersonGroupAsync(personGroupId); if (pgexists == null) { await _faceClient.CreatePersonGroupAsync(personGroupId, "My Friends"); } // Define Jose CreatePersonResult Josefriend = await _faceClient.CreatePersonAsync( // Id of the PersonGroup that the person belonged to personGroupId, // Name of the person "Jose" ); // Define Jose CreatePersonResult Aaronfriend = await _faceClient.CreatePersonAsync( // Id of the PersonGroup that the person belonged to personGroupId, // Name of the person "Aaron" ); // Directory contains image files of Anna const string JoseImageDir = @"C:\Users\joseo\source\repos\FutureofWork-ServTechAPJ2018\FutureofWork-ServTech2018APJ\LiveCameraSample\Pictures\Jose\"; foreach (string imagePath in Directory.GetFiles(JoseImageDir, "*.jpg")) { using (Stream s = File.OpenRead(imagePath)) { // Detect faces in the image and add to Anna await _faceClient.AddPersonFaceAsync( personGroupId, Josefriend.PersonId, s); } } // Do the same for Bill and Clare const string AaronImageDir = @"C:\Users\joseo\source\repos\FutureofWork-ServTechAPJ2018\FutureofWork-ServTech2018APJ\LiveCameraSample\Pictures\Aaron\"; foreach (string imagePath in Directory.GetFiles(AaronImageDir, "*.jpg")) { using (Stream s = File.OpenRead(imagePath)) { // Detect faces in the image and add to Anna await _faceClient.AddPersonFaceAsync( personGroupId, Aaronfriend.PersonId, s); } } // Do the same for Bill and Clare await _faceClient.TrainPersonGroupAsync(personGroupId); TrainingStatus trainingStatus = null; while (true) { trainingStatus = await _faceClient.GetPersonGroupTrainingStatusAsync(personGroupId); if (trainingStatus.Status != Status.Running) { break; } await Task.Delay(1000); } Console.Write("Training successfully completed"); }
public static async Task Train() { FaceAPI.FaceServiceClient _faceClient = new FaceAPI.FaceServiceClient("952a5cbdd78845948079fe7e2c61807d", "https://australiaeast.api.cognitive.microsoft.com/face/v1.0"); string personGroupId = "myfriendsServtechAPJ"; await _faceClient.CreatePersonGroupAsync(personGroupId, "My Friends"); // Define Jose CreatePersonResult Josefriend = await _faceClient.CreatePersonAsync( // Id of the PersonGroup that the person belonged to personGroupId, // Name of the person "Jose" ); // Define Jose CreatePersonResult Aaronfriend = await _faceClient.CreatePersonAsync( // Id of the PersonGroup that the person belonged to personGroupId, // Name of the person "Aaron" ); // Directory contains image files of Anna const string JoseImageDir = @"C:\Users\joseo\source\repos\FutureofWork-ServTechAPJ2018\FutureofWork-ServTech2018APJ\LiveCameraSample\Pictures\Jose\"; foreach (string imagePath in Directory.GetFiles(JoseImageDir, "*.jpg")) { using (Stream s = File.OpenRead(imagePath)) { // Detect faces in the image and add to Anna await _faceClient.AddPersonFaceAsync( personGroupId, Josefriend.PersonId, s); } } // Do the same for Bill and Clare const string AaronImageDir = @"C:\Users\joseo\source\repos\FutureofWork-ServTechAPJ2018\FutureofWork-ServTech2018APJ\LiveCameraSample\Pictures\Aaron\"; foreach (string imagePath in Directory.GetFiles(AaronImageDir, "*.jpg")) { using (Stream s = File.OpenRead(imagePath)) { // Detect faces in the image and add to Anna await _faceClient.AddPersonFaceAsync( personGroupId, Aaronfriend.PersonId, s); } } // Do the same for Bill and Clare await _faceClient.TrainPersonGroupAsync(personGroupId); FaceAPI.Contract.TrainingStatus trainingStatus = null; while (true) { trainingStatus = await _faceClient.GetPersonGroupTrainingStatusAsync(personGroupId); if (trainingStatus.Status != Status.Running) { break; } await Task.Delay(1000); } Console.Write("Training successfully completed"); }