Example #1
0
        private async void GetEmotionResultForImage(string filePath)
        {
            var fileStream = File.OpenRead(filePath);

            var emotionServiceClient = new EmotionServiceClient(
                ConfigurationManager.AppSettings.Get("EmotionApiKey"),
                ConfigurationManager.AppSettings.Get("EmotionApiEndpoint"));

            var result = await emotionServiceClient.RecognizeAsync(fileStream);

            var emotions = new List <string>();

            foreach (var emotion in result)
            {
                var keyValuePairs  = emotion.Scores.ToRankedList();
                var activeEmotions = keyValuePairs.Where(x => x.Value > 0.01).OrderByDescending(x => x.Value);

                foreach (var activeEmotion in activeEmotions)
                {
                    var emotionInPercent = (activeEmotion.Value * 100).ToString("#0.##");
                    emotions.Add($"{activeEmotion.Key} {emotionInPercent}%");
                }
            }

            var resultWindow = new ResultWindow
            {
                InputImage = new BitmapImage(new Uri(filePath)),
                Attributes = emotions,
                Owner      = this
            };

            resultWindow.ShowDialog();

            fileStream.Dispose();
        }
Example #2
0
        private async void GetFaceResultForImage(string filePath)
        {
            var fileStream = File.OpenRead(filePath);

            var faceServiceClient = new FaceServiceClient(
                ConfigurationManager.AppSettings.Get("FaceApiKey"),
                ConfigurationManager.AppSettings.Get("FaceApiEndpoint"));

            var result = await faceServiceClient.DetectAsync(
                fileStream,
                true,
                true,
                new List <FaceAttributeType>
            {
                FaceAttributeType.Accessories,
                FaceAttributeType.Age,
                FaceAttributeType.Blur,
                FaceAttributeType.Emotion,
                FaceAttributeType.Exposure,
                FaceAttributeType.FacialHair,
                FaceAttributeType.Gender,
                FaceAttributeType.Glasses,
                FaceAttributeType.Hair,
                FaceAttributeType.HeadPose,
                FaceAttributeType.Makeup,
                FaceAttributeType.Noise,
                FaceAttributeType.Occlusion,
                FaceAttributeType.Smile
            });

            var attributes = new List <string>();

            foreach (var face in result)
            {
                attributes.Add($"Age: {face.FaceAttributes.Age}");
                attributes.Add($"Gender: {face.FaceAttributes.Gender}");
                attributes.Add($"Glasses: {face.FaceAttributes.Glasses.ToString()}");
                attributes.Add($"Beard: {face.FaceAttributes.FacialHair.Beard}");
                attributes.Add($"Moustache: {face.FaceAttributes.FacialHair.Moustache}");
                attributes.Add($"Sideburns: {face.FaceAttributes.FacialHair.Sideburns}");
            }

            var resultWindow = new ResultWindow
            {
                InputImage = new BitmapImage(new Uri(filePath)),
                Attributes = attributes,
                Owner      = this
            };

            resultWindow.ShowDialog();

            fileStream.Dispose();
        }
Example #3
0
        private void PresentVisionResult(AnalysisResult result, string imageUri)
        {
            var attributes = new List <string> {
                result.Description.Captions.First().Text
            };

            var resultWindow = new ResultWindow
            {
                InputImage = new BitmapImage(new Uri(imageUri)),
                Attributes = attributes,
                Owner      = this
            };

            resultWindow.ShowDialog();
            resultWindow.InputImage = null;
        }