Esempio n. 1
0
        private ObservableCollection <EmoEmotion> ProccessEmotions(Emotion scores, EmoFace emoFace)
        {
            var emotionList = new ObservableCollection <EmoEmotion>();
            var properties  = scores.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);


            var filterProperties = properties.Where(p => p.PropertyType == typeof(double));

            var emotype = EmoEmotionEnum.Undetermined;

            foreach (var prop in filterProperties)
            {
                if (!Enum.TryParse <EmoEmotionEnum>(prop.Name, out emotype))
                {
                    emotype = EmoEmotionEnum.Undetermined;
                }

                var emoEmotion = new EmoEmotion()
                {
                    Score       = Convert.ToSingle(prop.GetValue(scores)),
                    EmotionType = emotype,
                    Face        = emoFace
                };

                emotionList.Add(emoEmotion);
            }

            return(emotionList);
        }
        private string RetornaMaiorSentimento(Emotion emotion)
        {
            string maiorSentimento = "Não definido";
            double maiorNumero     = 0;

            PropertyInfo[] info = emotion.GetType().GetProperties();
            foreach (PropertyInfo propInfo in info)
            {
                if (propInfo.PropertyType == typeof(double))
                {
                    double propValue = (double)(propInfo.GetValue(emotion, null));
                    if (propValue > maiorNumero)
                    {
                        maiorNumero = propValue;
                        switch (propInfo.Name)
                        {
                        case ("Anger"):
                            maiorSentimento = "Raiva";
                            break;

                        case ("Contempt"):
                            maiorSentimento = "Desprezo";
                            break;

                        case ("Disgust"):
                            maiorSentimento = "Desgosto";
                            break;

                        case ("Fear"):
                            maiorSentimento = "Medo";
                            break;

                        case ("Happiness"):
                            maiorSentimento = "Felicidade";
                            break;

                        case ("Neutral"):
                            maiorSentimento = "Neutro";
                            break;

                        case ("Sadness"):
                            maiorSentimento = "Tristeza";
                            break;

                        case ("Surprise"):
                            maiorSentimento = "Surpresa";
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            return(maiorSentimento);
        }
Esempio n. 3
0
        private void FindHighestEmotion(Emotion detectedEmotions)
        {
            var    properties = detectedEmotions.GetType().GetProperties().ToList();
            double highestEmotionConfidence = 0;
            double confidence;

            properties.ForEach(property =>
            {
                confidence = (double)property.GetValue(detectedEmotions, null);
                if (confidence > highestEmotionConfidence)
                {
                    highestEmotionConfidence = confidence;
                    HighestEmotion           = property.Name;
                }
            });
        }
Esempio n. 4
0
        private void ExtractEmotions(Emotion emotion, FaceModel face)
        {
            face.Emotions = new ObservableCollection <EmotionModel>();

            var properties = emotion.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            properties = properties.Where(x => x.PropertyType == typeof(double)).ToArray();

            foreach (var prop in properties)
            {
                var typeEmotion = EmotionEnum.Undetermined;
                Enum.TryParse <EmotionEnum>(prop.Name, out typeEmotion);

                face.Emotions.Add(new EmotionModel()
                {
                    Score = (double)prop.GetValue(emotion),
                    Type  = typeEmotion,
                    Face  = face
                });
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the facial expression with the highest value
        /// </summary>
        /// <param name="em"></param>
        /// <returns></returns>
        private string GetFacialExpression(Emotion em)
        {
            string retVal = string.Empty;
            double maxVal = 0;

            Type emotionType = em.GetType();

            foreach (PropertyInfo propertyInfo in emotionType.GetProperties())
            {
                string propName        = propertyInfo.Name;
                object propValAsObject = propertyInfo.GetValue(em);

                if (propValAsObject is double && maxVal < (double)propValAsObject)
                {
                    maxVal = (double)propValAsObject;
                    retVal = propName;
                }
            }

            return(retVal);
        }