public void UpdateEmotion(EmotionScores scores)
        {
            EmotionData topEmotion = EmotionServiceHelper.ScoresToEmotionData(scores).OrderByDescending(d => d.EmotionScore).First();

            this.filledBar.Background            = this.emotionToColorMapping[topEmotion.EmotionName];
            this.emptySpaceRowDefinition.Height  = new GridLength(1 - topEmotion.EmotionScore, Windows.UI.Xaml.GridUnitType.Star);
            this.filledSpaceRowDefinition.Height = new GridLength(topEmotion.EmotionScore, Windows.UI.Xaml.GridUnitType.Star);
        }
        public void ShowEmotionData(Emotion emotion)
        {
            this.EmotionData = EmotionServiceHelper.ScoresToEmotionData(emotion.Scores).OrderByDescending(e => e.EmotionScore).ToArray();

            this.DataContext = this;

            this.emotionGrid.Visibility   = Visibility.Visible;
            this.captionCanvas.Visibility = Visibility.Visible;
        }
Beispiel #3
0
        public void UpdateEmotion(EmotionScores scores)
        {
            EmotionData topEmotion = EmotionServiceHelper.ScoresToEmotionData(scores).OrderByDescending(d => d.EmotionScore).First();
            string      label = "", emoji = "";

            switch (topEmotion.EmotionName)
            {
            case "Anger":
                label = "Angry";
                emoji = "\U0001f620";
                break;

            case "Contempt":
                label = "Contemptuous";
                emoji = "\U0001f612";
                break;

            case "Disgust":
                label = "Disgusted";
                emoji = "\U0001f627";
                break;

            case "Fear":
                label = "Afraid";
                emoji = "\U0001f628";
                break;

            case "Happiness":
                label = "Happy";
                emoji = "\U0001f60a";
                break;

            case "Neutral":
                label = "Neutral";
                emoji = "\U0001f614";
                break;

            case "Sadness":
                label = "Sad";
                emoji = "\U0001f622";
                break;

            case "Surprise":
                label = "Surprised";
                emoji = "\U0001f632";
                break;

            default:
                break;
            }

            this.emotionEmoji.Text = emoji;
            this.emotionText.Text  = label;
        }
Beispiel #4
0
 private static async Task AnalyzeEmotionAsync(Func <Task <Stream> > imageStreamCallback, List <Emotion> faceEmotions)
 {
     faceEmotions.AddRange(await EmotionServiceHelper.RecognizeAsync(imageStreamCallback));
 }
Beispiel #5
0
        private async Task ProcessCameraCapture(ImageAnalyzer e)
        {
            if (e == null)
            {
                this.isProcessingPhoto = false;
                return;
            }

            if (e.DetectedEmotion.Any())
            {
                // Update the average emotion response
                Scores averageScores = new Scores
                {
                    Happiness = e.DetectedEmotion.Average(em => em.Scores.Happiness),
                    Anger     = e.DetectedEmotion.Average(em => em.Scores.Anger),
                    Sadness   = e.DetectedEmotion.Average(em => em.Scores.Sadness),
                    Contempt  = e.DetectedEmotion.Average(em => em.Scores.Contempt),
                    Disgust   = e.DetectedEmotion.Average(em => em.Scores.Disgust),
                    Neutral   = e.DetectedEmotion.Average(em => em.Scores.Neutral),
                    Fear      = e.DetectedEmotion.Average(em => em.Scores.Fear),
                    Surprise  = e.DetectedEmotion.Average(em => em.Scores.Surprise)
                };

                double positiveEmotionResponse = Math.Min(averageScores.Happiness + averageScores.Surprise, 1);
                double negativeEmotionResponse = Math.Min(averageScores.Sadness + averageScores.Fear + averageScores.Disgust + averageScores.Contempt, 1);
                double netResponse             = ((positiveEmotionResponse - negativeEmotionResponse) * 0.5) + 0.5;

                this.sentimentControl.Sentiment = netResponse;

                // show captured faces and their emotion
                if (this.emotionFacesGrid.Visibility == Visibility.Visible)
                {
                    foreach (var face in e.DetectedEmotion)
                    {
                        // Get top emotion on this face
                        EmotionData topEmotion = EmotionServiceHelper.ScoresToEmotionData(face.Scores).OrderByDescending(em => em.EmotionScore).First();

                        // Crop this face
                        Rectangle rect = face.FaceRectangle;
                        double    heightScaleFactor = 1.8;
                        double    widthScaleFactor  = 1.8;
                        Rectangle biggerRectangle   = new Rectangle
                        {
                            Height = Math.Min((int)(rect.Height * heightScaleFactor), e.DecodedImageHeight),
                            Width  = Math.Min((int)(rect.Width * widthScaleFactor), e.DecodedImageWidth)
                        };
                        biggerRectangle.Left = Math.Max(0, rect.Left - (int)(rect.Width * ((widthScaleFactor - 1) / 2)));
                        biggerRectangle.Top  = Math.Max(0, rect.Top - (int)(rect.Height * ((heightScaleFactor - 1) / 1.4)));

                        ImageSource croppedImage = await Util.GetCroppedBitmapAsync(e.GetImageStreamCallback, biggerRectangle);

                        // Add the face and emotion to the collection of faces
                        if (croppedImage != null && biggerRectangle.Height > 0 && biggerRectangle.Width > 0)
                        {
                            if (this.EmotionFaces.Count >= 9)
                            {
                                this.EmotionFaces.Clear();
                            }

                            this.EmotionFaces.Add(new EmotionExpressionCapture {
                                CroppedFace = croppedImage, TopEmotion = topEmotion.EmotionName
                            });
                        }
                    }
                }
            }

            this.isProcessingPhoto = false;
        }