Esempio n. 1
0
        public static Tuple <string, float> GetDominantEmotion(Microsoft.ProjectOxford.Common.Contract.EmotionScores scores)
        {
            var Item = scores.ToRankedList().OrderByDescending(o => o.Value).Select(kv => new Tuple <string, float>(kv.Key, kv.Value)).FirstOrDefault();

            if (Item != null && Item.Item1 == "Neutral")
            {
                var score2 = scores.ToRankedList().OrderByDescending(o => o.Value).Take(2).Select(kv => new Tuple <string, float>(kv.Key, kv.Value)).ToList();
                if (score2 != null)
                {
                    var nonWinner = score2.OrderBy(o => o.Item2).FirstOrDefault();
                    var Winner    = score2.OrderByDescending(o => o.Item2).FirstOrDefault();

                    if (Winner.Item2 - nonWinner.Item2 < 0.9 && Winner.Item2 < 0.7)
                    {
                        return(nonWinner);
                    }
                }
            }


            return(scores.ToRankedList().OrderByDescending(o => o.Value).Select(kv => new Tuple <string, float>(kv.Key, kv.Value)).First());
        }
Esempio n. 2
0
        private void _setEmotionsToInterface(Microsoft.ProjectOxford.Common.Contract.EmotionScores emotions)
        {
            HapinessTextBlock.Text = Math.Round((double)(emotions.Happiness) * 100, 4) + " %";
            SadnessTextBlock.Text  = Math.Round((double)(emotions.Sadness) * 100, 4) + " %";
            SurpriseTextBlock.Text = Math.Round((double)(emotions.Surprise) * 100, 4) + " %";
            NeutralTextBlock.Text  = Math.Round((double)(emotions.Neutral) * 100, 4) + " %";
            AngerTextBlock.Text    = Math.Round((double)(emotions.Anger) * 100, 4) + " %";
            ContemptTextBlock.Text = Math.Round((double)(emotions.Contempt) * 100, 4) + " %";
            DisgustTextBlock.Text  = Math.Round((double)(emotions.Disgust) * 100, 4) + " %";
            FearTextBlock.Text     = Math.Round((double)(emotions.Fear) * 100, 4) + " %";

            var bestEmotion = emotions.ToRankedList().FirstOrDefault().Key;

            BestEmotionTextBlock.Text = $"You are {bestEmotion}!";

            _setEmotionIcon(bestEmotion);
        }
Esempio n. 3
0
        async void DetectEmotions()
        {
            // tablica emocji - zawiera emocje dla każdej osoby na zdjęciu
            Emotion[] emotionResult;
            var       storageFile = photo;

            // zamieniamy zdjęcie na ciąg bitów
            var randomAccessStream = await storageFile.OpenReadAsync();

            // wysyłamy zdjęcie do Azure i dostajemy spowrotem emocje
            emotionResult = await emotionServiceClient.RecognizeAsync(randomAccessStream.AsStream());

            // zapisujemy wyniki do zmiennej
            Microsoft.ProjectOxford.Common.Contract.EmotionScores score = emotionResult[0].Scores;


            // wpisujemy do textboxa wynik emocji w procentach zaokrąglone do 4 miejsc po przecinku
            mojTextbox.Text = "Your Emotions are : \n" +

                              "Happiness: " + Math.Round((double)(score.Happiness) * 100, 4) + " %" + "\n" +

                              "Sadness: " + Math.Round((double)(score.Sadness) * 100, 4) + " %" + "\n" +

                              "Surprise: " + Math.Round((double)(score.Surprise) * 100, 4) + " %" + "\n" +

                              "Neutral: " + Math.Round((double)(score.Neutral) * 100, 4) + " %" + "\n" +

                              "Anger: " + Math.Round((double)(score.Anger) * 100, 4) + " %" + "\n" +

                              "Contempt: " + Math.Round((double)(score.Contempt) * 100, 4) + " %" + "\n" +

                              "Disgust: " + Math.Round((double)(score.Disgust) * 100, 4) + " %" + "\n" +

                              "Fear: " + Math.Round((double)(score.Fear) * 100, 4) + " %" + "\n";

            // Linq które wybiera najbardziej znaczący wynik, czyli emocję która ma najwięcej punktów
            var lista = score.ToRankedList().FirstOrDefault().Key;

            moj2.Text = (lista.ToString());
        }
Esempio n. 4
0
        private static (EmotionValue emotionValue, double emotionScore) GetEmotionValueFromScores(Microsoft.ProjectOxford.Common.Contract.EmotionScores scores)
        {
            var highestEmotionScore = scores.ToRankedList().First();

            return(emotionValue : (EmotionValue)Enum.Parse(typeof(EmotionValue), highestEmotionScore.Key), emotionScore : highestEmotionScore.Value);
        }
 public static Tuple <string, float> GetDominantEmotion(Microsoft.ProjectOxford.Common.Contract.EmotionScores scores)
 {
     return(scores.ToRankedList().Select(kv => new Tuple <string, float>(kv.Key, kv.Value)).First());
 }