internal static string GetMessageFromException(Exception ex) { string errorDetails = ex.Message; FaceAPIException faceApiException = ex as FaceAPIException; if (faceApiException?.ErrorMessage != null) { errorDetails = faceApiException.ErrorMessage; } Microsoft.ProjectOxford.Common.ClientException commonException = ex as Microsoft.ProjectOxford.Common.ClientException; if (commonException?.Error?.Message != null) { errorDetails = commonException.Error.Message; } Microsoft.ProjectOxford.Vision.ClientException visionException = ex as Microsoft.ProjectOxford.Vision.ClientException; if (visionException?.Error?.Message != null) { errorDetails = visionException.Error.Message; } HttpOperationException httpException = ex as HttpOperationException; if (httpException?.Response?.ReasonPhrase != null) { errorDetails = string.Format("{0}. The error message was \"{1}\".", ex.Message, httpException?.Response?.ReasonPhrase); } return(errorDetails); }
internal static string GetMessageFromException(Exception ex) { string errorDetails = ex.Message; FaceAPIException faceApiException = ex as FaceAPIException; if (faceApiException?.ErrorMessage != null) { errorDetails = faceApiException.ErrorMessage; } ClientException commonException = ex as ClientException; if (commonException?.Error?.Message != null) { errorDetails = commonException.Error.Message; } Microsoft.ProjectOxford.Vision.ClientException visionException = ex as Microsoft.ProjectOxford.Vision.ClientException; if (visionException?.Error?.Message != null) { errorDetails = visionException.Error.Message; } return(errorDetails); }
private static async Task <Face> GetFirstFaceAsync(Stream image, TraceWriter log) { var faceClient = new FaceServiceClient( Environment.GetEnvironmentVariable("FaceAPIKey", EnvironmentVariableTarget.Process), Environment.GetEnvironmentVariable("FaceAPIEndpoint", EnvironmentVariableTarget.Process)); try { Face[] detectResult = await faceClient.DetectAsync( image, returnFaceAttributes : new FaceAttributeType[] { FaceAttributeType.Age, FaceAttributeType.FacialHair, FaceAttributeType.Gender, FaceAttributeType.Smile, FaceAttributeType.Glasses }, returnFaceLandmarks : true); if (detectResult.Length > 0) { Face firstFace = detectResult[0]; return(firstFace); } else { //TODO: no face - skonèit / vyvolat znovu capture? log.Info("No faces detected."); return(null); } } catch (Exception ex) when((ex is AggregateException && ex.InnerException is FaceAPIException) || ex is FaceAPIException) { FaceAPIException exp = null; if (ex is FaceAPIException) { exp = (FaceAPIException)ex; } else if (ex is AggregateException && ex.InnerException is FaceAPIException) { exp = (FaceAPIException)ex.InnerException; } log.Error("Detection Error: " + exp?.ErrorMessage); // pokud bude code 429, poèkat chvíli a spustit znovu return(null); } }
public async Task RegisterKnownUsersAsync() { try { #region Create new Person Group //try //{ // // Delete the person group if it already exists. // PersonGroup group = await faceServiceClient.GetPersonGroupAsync(personGroupId); // Debug.WriteLine("Person Group " + personGroupId + " already exists, deleting it."); // await faceServiceClient.DeletePersonGroupAsync(personGroupId); //} //catch (Exception) //{ // // Hmmm, that exception tasted yummy. //} //// create an empty person group with an Id and a friendly display name. //await faceServiceClient.CreatePersonGroupAsync(personGroupId, personGroupName); #endregion #region Upload images for each person ////StorageFolder knownImagesBaseFolder = await KnownFolders.CameraRoll.GetFolderAsync("knownimages"); //StorageFolder knownImagesBaseFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(@"Assets\knownimages"); //var knownImageFolders = await knownImagesBaseFolder.GetFoldersAsync(); //foreach (StorageFolder person in knownImageFolders) //{ // Debug.WriteLine(person.Name); // // define a person in the group // CreatePersonResult friend = await faceServiceClient.CreatePersonAsync(personGroupId, person.Name); // IReadOnlyList<StorageFile> files = await person.GetFilesAsync(); // // add the known images of the person // foreach (StorageFile file in files) // { // using (Stream s = File.OpenRead(file.Path)) // { // Debug.WriteLine("Uploading " + file.Path); // // detect faces in the image and add to person // await faceServiceClient.AddPersonFaceAsync(personGroupId, friend.PersonId, s); // } // } //} #endregion #region Train the model. //await faceServiceClient.TrainPersonGroupAsync(personGroupId); //// wait until the training is complete. //TrainingStatus trainingstatus = null; //while (true) //{ // trainingstatus = await faceServiceClient.GetPersonGroupTrainingStatusAsync(personGroupId); // if (trainingstatus.Status == Status.Succeeded) // { // Debug.WriteLine("Training complete."); // break; // } // Debug.WriteLine("Wating for training to complete...."); // await Task.Delay(10000); //} #endregion } catch (Exception ex) { #region Track and display errors FaceAPIException fex = (FaceAPIException)ex.InnerException; Debug.WriteLine(ex.InnerException.Message); Debug.WriteLine(fex.ErrorCode); Debug.WriteLine(fex.ErrorMessage); #endregion } KnownImagesRegistered = true; //App.Controller.Camera.PhotoTaken += Camera_PhotoTaken; }