コード例 #1
0
        protected override async void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(sender, e);

            if (e.PropertyName == nameof(FaceDetected) && FaceDetected != null)
            {
                try
                {
                    IsLoading = true;
                    RaisePropertyChanged(nameof(IsLoading));

                    IEnumerable <FaceModel> faces = await Task.Run(async() => await AzureApi.GetFacesAsync(FaceDetected));

                    foreach (FaceModel face in faces)
                    {
                        StringBuilder builder = new StringBuilder();
                        builder.AppendLine($"Age: {face.FaceAttributes.Age}");
                        builder.AppendLine($"Gender: {face.FaceAttributes.Gender}");
                        string hairColor = face.FaceAttributes.Hair.HairColor.OrderByDescending(hc => hc.Confidence).FirstOrDefault().Color;
                        builder.AppendLine($"HairColor: {hairColor}");
                        builder.AppendLine($"Beard: {face.FaceAttributes.FacialHair.Beard}");
                        builder.AppendLine($"Moustache: {face.FaceAttributes.FacialHair.Moustache}");
                        builder.AppendLine($"Smile: {face.FaceAttributes.Smile}");

                        builder.AppendLine();

                        builder.AppendLine("--EMOTIONS--");
                        builder.AppendLine($"Anger: {face.FaceAttributes.Emotion.Anger}");
                        builder.AppendLine($"Contempt: {face.FaceAttributes.Emotion.Contempt}");
                        builder.AppendLine($"Disgust: {face.FaceAttributes.Emotion.Disgust}");
                        builder.AppendLine($"Fear: {face.FaceAttributes.Emotion.Fear}");
                        builder.AppendLine($"Happiness: {face.FaceAttributes.Emotion.Happiness}");
                        builder.AppendLine($"Neutral: {face.FaceAttributes.Emotion.Neutral}");
                        builder.AppendLine($"Sadness: {face.FaceAttributes.Emotion.Sadness}");
                        builder.AppendLine($"Surprise: {face.FaceAttributes.Emotion.Surprise}");

                        _viewModelService.ShowMessage(builder.ToString(), "Face informations", MessageBoxButton.OK);
                    }
                }
                finally
                {
                    IsLoading = false;
                    RaisePropertyChanged(nameof(IsLoading));
                }
            }
        }
コード例 #2
0
        static async Task AnalyzeSuspect(string imageFilePath)
        {
            byte[] byteData = GetImageAsByteArray(imageFilePath);
            IEnumerable <FaceModel> faces = await AzureApi.GetFacesAsync(byteData);

            if (!faces.Any())
            {
                System.Console.WriteLine("No suspect found.");
                System.Console.WriteLine();
                return;
            }

            int suspectNumber = 1;

            foreach (FaceModel face in faces)
            {
                PrintFaceDetails(face, suspectNumber++);
            }
        }