//private static int GetDefaultResultIndex(IList<DetectedFace> result)
        //{
        //    if (result == null)
        //        throw new ArgumentNullException();
        //    else if (result.Count == 0)
        //        throw new ArgumentOutOfRangeException();
        //    else if (result.Count == 1)
        //        return 0;


        //    int i = 0, index = 0;
        //    double maxArea = -1d;
        //    double area = 0;

        //    foreach (DetectedFace df in result)
        //    {
        //        area = df.FaceRectangle.Height * df.FaceRectangle.Width;

        //        if (maxArea < area)
        //        {
        //            maxArea = area;
        //            index = i;
        //        }

        //        i++;
        //    }

        //    return index;
        //}

        //public static async Task<EmotionData[]> RecognizeAsync(string url)
        //{
        //    // Implement: PBI 2, Task 3, Step 5
        //    // You should make a call to the EmotionServiceClient object that support an URL as parameter to identify emotions
        //    return await RunTaskWithAutoRetryOnQuotaLimitExceededError<EmotionData[]>(async () => await emotionClient.RecognizeAsync(url));
        //}

        public static IEnumerable <EmotionData> ScoresToEmotionData(EmotionScores scores)
        {
            // Implement: PBI 2, Task 3, Step 4
            // Create a list of emotions and emotion scores to return as a results.
            // Use the JSON object result of the EmotionAPI_Test project to undestand how to build this list.
            List <EmotionData> result = new List <EmotionData>();

            result.Add(new EmotionData {
                EmotionName = "Anger", EmotionScore = scores.Anger
            });
            result.Add(new EmotionData {
                EmotionName = "Contempt", EmotionScore = scores.Contempt
            });
            result.Add(new EmotionData {
                EmotionName = "Disgust", EmotionScore = scores.Disgust
            });
            result.Add(new EmotionData {
                EmotionName = "Fear", EmotionScore = scores.Fear
            });
            result.Add(new EmotionData {
                EmotionName = "Happiness", EmotionScore = scores.Happiness
            });
            result.Add(new EmotionData {
                EmotionName = "Neutral", EmotionScore = scores.Neutral
            });
            result.Add(new EmotionData {
                EmotionName = "Sadness", EmotionScore = scores.Sadness
            });
            result.Add(new EmotionData {
                EmotionName = "Surprise", EmotionScore = scores.Surprise
            });

            return(result);
        }
Ejemplo n.º 2
0
        private void UpdateEmotionTimelineUI(ImageAnalyzer e)
        {
            if (!e.DetectedFaces.Any())
            {
                this.ShowTimelineFeedbackForNoFaces();
            }
            else
            {
                EmotionScores averageScores = new EmotionScores
                {
                    Happiness = e.DetectedFaces.Average(f => f.FaceAttributes.Emotion.Happiness),
                    Anger     = e.DetectedFaces.Average(f => f.FaceAttributes.Emotion.Anger),
                    Sadness   = e.DetectedFaces.Average(f => f.FaceAttributes.Emotion.Sadness),
                    Contempt  = e.DetectedFaces.Average(f => f.FaceAttributes.Emotion.Contempt),
                    Disgust   = e.DetectedFaces.Average(f => f.FaceAttributes.Emotion.Disgust),
                    Neutral   = e.DetectedFaces.Average(f => f.FaceAttributes.Emotion.Neutral),
                    Fear      = e.DetectedFaces.Average(f => f.FaceAttributes.Emotion.Fear),
                    Surprise  = e.DetectedFaces.Average(f => f.FaceAttributes.Emotion.Surprise)
                };

                this.emotionDataTimelineControl.DrawEmotionData(averageScores);

                foreach (var person in e.IdentifiedPersons)
                {
                    Face face = (Face)e.DetectedFaces.FirstOrDefault(f => f.FaceId == person.FaceId);
                    if (face != null)
                    {
                        this.PersistEmotionData(person.Person.Name, "restaurant1", GetNetResponseScore(face.FaceAttributes.Emotion));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private ObservableCollection <EmoEmotion> ProcessEmotions(EmotionScores 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(float));
            var filterProperties = from p in properties
                                   where p.PropertyType == typeof(float)
                                   select p;

            var emoType = EmoEmotionEnum.Undetermined;

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

                var emoEmotion = new EmoEmotion();
                emoEmotion.Score       = (float)prop.GetValue(scores);
                emoEmotion.EmotionType = emoType;
                emoEmotion.Face        = emoface;

                emotionList.Add(emoEmotion);
            }

            return(emotionList);
        }
        public async Task <string> Face_Analyse(Stream imageFileStream)
        {
            //Count Faces
            Face[] faces = await faceServiceClient.DetectAsync(imageFileStream, returnFaceId : true, returnFaceLandmarks : false, returnFaceAttributes : faceAttributes);

            if (faces.Count() > 1)
            {
                throw new Exception("Zu viele Gesichter erkannt...");
            }
            if (faces.Count() < 1)
            {
                throw new Exception("Kein Gesicht erkannt...");
            }

            //Emotion für Gesicht auslesen
            EmotionScores emotionScores            = faces[0].FaceAttributes.Emotion;
            Dictionary <string, float> emotionList = new Dictionary <string, float>(emotionScores.ToRankedList());

            //Zusammensetzen der Rückgabe
            StringBuilder sb = new StringBuilder();

            sb.Append("<div><table>");
            foreach (KeyValuePair <string, float> element in emotionList)
            {
                sb.Append(String.Format("<tr><td>{0}: " + "</td><td>" + " {1}%" + "</td></tr>", Translate(element.Key), (element.Value * 100).ToString()));
            }
            sb.Append("</table></div>");

            //Rückgabe
            return(Newtonsoft.Json.JsonConvert.SerializeObject(sb.ToString()));
        }
Ejemplo n.º 5
0
        private ObservableCollection <Models.Emotion> ProccesEmotions(EmotionScores emotionScores, Face face)
        {
            var emotionList = new ObservableCollection <Models.Emotion>();

            var properties       = emotionScores.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            var filterProperties = properties.Where(p => p.PropertyType == typeof(float));

            var emotionType = EmotionEnum.Undeterminated;

            foreach (var prop in filterProperties)
            {
                if (!Enum.TryParse <EmotionEnum>(prop.Name, out emotionType))
                {
                    emotionType = EmotionEnum.Undeterminated;
                }
                var emotion = new Models.Emotion
                {
                    Score       = (float)prop.GetValue(emotionScores),
                    EmotionType = emotionType,
                    Face        = face
                };

                emotionList.Add(emotion);
            }

            return(emotionList);
        }
Ejemplo n.º 6
0
        private ObservableCollection <EmoEmotion> ProcessEmotions(EmotionScores scores, EmoFace emoface)
        {
            //C# es un lenguaje capaz de autodescribirse, es capaz de describir cada uno de los objetos que tiene, sabe como estan construidos cada uno de esos objetos(REFLECTION).
            var emotionList      = new ObservableCollection <EmoEmotion>();
            var properties       = scores.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); //devuelve toda la informacion del tipo de datos que tiene esta variable
            var filterProperties = properties.Where(p => p.PropertyType == typeof(float));                      //En toda Coleccion se puede meter Linq. | Quiero todas las propiedades de tipo float.
                                                                                                                //from p in properties where p.PropertyType == typeof(float) select p;

            var emotype = EmoEmotionEnum.Undetermined;                                                          //variable auxiliar

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

                var emoEmotion = new EmoEmotion();
                emoEmotion.Score       = (float)prop.GetValue(scores);
                emoEmotion.EmotionType = emotype;
                emoEmotion.Face        = emoface;
                emotionList.Add(emoEmotion);
            }

            return(emotionList);
        }
Ejemplo n.º 7
0
        static Image GetCardImageAndScores(EmotionScores scores, out double score)
        {
            NormalizeScores(scores);

            var cardBack = "neutral.png";

            score = scores.Neutral;
            const int angerBoost = 2, happyBoost = 4;

            if (scores.Surprise > 10)
            {
                cardBack = "surprised.png";
                score    = scores.Surprise;
            }
            else if (scores.Anger > 10)
            {
                cardBack = "angry.png";
                score    = scores.Anger * angerBoost;
            }
            else if (scores.Happiness > 50)
            {
                cardBack = "happy.png";
                score    = scores.Happiness * happyBoost;
            }

            return(Image.FromFile(GetFullImagePath(cardBack)));
        }
Ejemplo n.º 8
0
        public async void SaveCurrentEmotionsToFolder(EmotionScores emotions, Geoposition currentPosition, string photoFileName, string folderName = "EmotionDataFolder")
        {
            var currentEmotionData = new EmotionsData()
            {
                Anger    = emotions.Anger,
                Sadness  = emotions.Sadness,
                Neutral  = emotions.Neutral,
                Fear     = emotions.Fear,
                Disgust  = emotions.Disgust,
                Contempt = emotions.Contempt,
                Hapiness = emotions.Happiness,
                Suprise  = emotions.Surprise,
            };

            var bestEmotionKey   = emotions.ToRankedList().FirstOrDefault().Key;
            var bestEmotionValue = emotions.ToRankedList().FirstOrDefault().Value;

            currentEmotionData.BestEmotionName  = bestEmotionKey;
            currentEmotionData.BestEmotionScore = bestEmotionValue;
            //currentEmotionData.position = currentPosition;
            currentEmotionData.Longitude     = currentPosition.Coordinate.Longitude;
            currentEmotionData.Latitude      = currentPosition.Coordinate.Latitude;
            currentEmotionData.PhotoFileName = photoFileName;

            currentEmotionData.DateTaken = DateTime.Now;
            string fileName = DateTime.Now.ToString("yyyy-MM-dd--HH-mm-ss") + ".xml";
            await SerializationController.SaveObjectToXml <EmotionsData>(currentEmotionData, fileName, folderName);
        }
        public static async Task GenerateCard(
            [QueueTrigger("%input-queue%")] CardInfoMessage cardInfo,
            [Blob("%input-container%/{BlobName}", FileAccess.Read)] byte[] image,
            [Blob("%output-container%/{BlobName}", FileAccess.Write)] Stream outputBlob,
            TraceWriter log, ExecutionContext context)
        {
            Emotion[] faceDataArray = await RecognizeEmotionAsync(image, log);

            if (faceDataArray == null)
            {
                log.Error("No result from Emotion API");
                return;
            }

            if (faceDataArray.Length == 0)
            {
                log.Error("No face detected in image");
                return;
            }

            var faceData = faceDataArray[0];

            var testscores = new EmotionScores {
                Happiness = 1
            };
            string cardPath = GetCardImageAndScores(faceDataArray[0].Scores, out double score, context.FunctionDirectory); // assume exactly one face

            MergeCardImage(cardPath, image, outputBlob, cardInfo.PersonName, cardInfo.Title, score);

            //SaveAsJpeg(card, outputBlob);
        }
Ejemplo n.º 10
0
        private ObservableCollection <EmoEmotion> ProcessEmotions(EmotionScores scores, EmoFace vFace)
        {
            ObservableCollection <EmoEmotion> lEmotion = new ObservableCollection <EmoEmotion>();

            var vProperties       = scores.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
            var vFilterProperties = vProperties.Where(x => x.PropertyType == typeof(float));

            var vEmoType = EmoEmotionEnum.Undertermined;

            foreach (var prop in vFilterProperties)
            {
                if (!Enum.TryParse <EmoEmotionEnum>(prop.Name, out vEmoType))
                {
                    vEmoType = EmoEmotionEnum.Undertermined;
                }

                var vEmotion = new EmoEmotion();
                vEmotion.Score       = (float)prop.GetValue(scores);
                vEmotion.EmotionType = vEmoType;
                //vEmotion.EmoFaceId = vFace.Id;
                vEmotion.Face = vFace;

                lEmotion.Add(vEmotion);
            }

            return(lEmotion);
        }
        static string GetCardImageAndScores(EmotionScores scores, out double score, string functionDirectory)
        {
            NormalizeScores(scores);

            var cardBack = "neutral.png";

            score = scores.Neutral;
            const int angerBoost = 2, happyBoost = 4;

            if (scores.Surprise > 10)
            {
                cardBack = "surprised.png";
                score    = scores.Surprise;
            }
            else if (scores.Anger > 10)
            {
                cardBack = "angry.png";
                score    = scores.Anger * angerBoost;
            }
            else if (scores.Happiness > 50)
            {
                cardBack = "happy.png";
                score    = scores.Happiness * happyBoost;
            }

            var path = Path.Combine(functionDirectory, "..\\", AssetsFolderLocation, cardBack);

            return(Path.GetFullPath(path));
        }
Ejemplo n.º 12
0
        public static float DirectionTypeToFaceApiProp(EmotionType type, EmotionScores emotion)
        {
            switch (type)
            {
            case EmotionType.Anger:
                return(emotion.Anger);

            case EmotionType.Contempt:
                return(emotion.Contempt);

            case EmotionType.Disgust:
                return(emotion.Disgust);

            case EmotionType.Fear:
                return(emotion.Fear);

            case EmotionType.Happiness:
                return(emotion.Happiness);

            case EmotionType.Neutral:
                return(emotion.Neutral);

            case EmotionType.Sadness:
                return(emotion.Sadness);

            case EmotionType.Surprise:
                return(emotion.Surprise);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 13
0
        private async Task <EmotionScores> DetectEmotionsManuallyAsync(NSData inputFile)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                await DisplayAlert("Network error",
                                   "Please check your network connection and retry.", "OK");

                return(null);
            }
            EmotionScores emotionScores = null;

            try
            {
                // Get emotions from the specified stream
                Emotion[] emotionResult = await
                                          emotionServiceClient.RecognizeAsync(new MemoryStream(inputFile.ToArray()));

                if (emotionResult != null)
                {
                    // Assuming the picture has one face, retrieve emotions for the
                    // first item in the returned array
                    emotionScores = emotionResult[0]?.Scores;
                }
                return(emotionScores);
            }
            catch (Exception ex)
            {
                if (emotionScores != null)
                {
                    await DisplayAlert("Error", ex.Message, "OK");
                }
                return(null);
            }
        }
Ejemplo n.º 14
0
        public static IEnumerable <EmotionData> ScoresToEmotionData(EmotionScores scores)
        {
            List <EmotionData> result = new List <EmotionData>();

            result.Add(new EmotionData {
                EmotionName = "Anger", EmotionScore = scores.Anger
            });
            result.Add(new EmotionData {
                EmotionName = "Contempt", EmotionScore = scores.Contempt
            });
            result.Add(new EmotionData {
                EmotionName = "Disgust", EmotionScore = scores.Disgust
            });
            result.Add(new EmotionData {
                EmotionName = "Fear", EmotionScore = scores.Fear
            });
            result.Add(new EmotionData {
                EmotionName = "Happiness", EmotionScore = scores.Happiness
            });
            result.Add(new EmotionData {
                EmotionName = "Neutral", EmotionScore = scores.Neutral
            });
            result.Add(new EmotionData {
                EmotionName = "Sadness", EmotionScore = scores.Sadness
            });
            result.Add(new EmotionData {
                EmotionName = "Surprise", EmotionScore = scores.Surprise
            });

            return(result);
        }
Ejemplo n.º 15
0
        private double GetNetResponseScore(EmotionScores emotionScores)
        {
            double positiveEmotionResponse = Math.Min(emotionScores.Happiness + emotionScores.Surprise, 1);
            double negativeEmotionResponse = Math.Min(emotionScores.Sadness + emotionScores.Fear + emotionScores.Disgust + emotionScores.Contempt, 1);
            double netResponse             = positiveEmotionResponse - negativeEmotionResponse;

            return(netResponse);
        }
Ejemplo n.º 16
0
 public static void NormalizeScores(EmotionScores scores)
 {
     scores.Anger     = RoundScore(scores.Anger);
     scores.Happiness = RoundScore(scores.Happiness);
     scores.Neutral   = RoundScore(scores.Neutral);
     scores.Sadness   = RoundScore(scores.Sadness);
     scores.Surprise  = RoundScore(scores.Surprise);
 }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
        public void UpdateEmotion(EmotionScores scores)
        {
            var topEmotion = scores.ToRankedList().First();

            this.filledBar.Background            = this.emotionToColorMapping[topEmotion.Key];
            this.emptySpaceRowDefinition.Height  = new GridLength(1 - topEmotion.Value, Windows.UI.Xaml.GridUnitType.Star);
            this.filledSpaceRowDefinition.Height = new GridLength(topEmotion.Value, Windows.UI.Xaml.GridUnitType.Star);
        }
Ejemplo n.º 19
0
        // Returns a string that describes the given face.

        private string FaceDescription(Face face)
        {
            StringBuilder sb = new StringBuilder();

            //sb.Append("Face: ");

            // Add the gender, age, and smile.
            //sb.Append(face.FaceAttributes.Gender);
            //sb.Append(Environment.NewLine);

            ///sb.Append(", ");
            ///sb.Append(String.Format("smile {0:F1}%, ", face.FaceAttributes.Smile * 100));

            // Add the emotions. Display all emotions over 10%.
            sb.Append("Emotion: ");
            EmotionScores emotionScores = face.FaceAttributes.Emotion;

            if (emotionScores.Anger >= 0.1f)
            {
                sb.Append(String.Format("anger {0:F1}%, ", emotionScores.Anger * 100));
            }
            if (emotionScores.Contempt >= 0.1f)
            {
                sb.Append(String.Format("contempt {0:F1}%, ", emotionScores.Contempt * 100));
            }
            if (emotionScores.Disgust >= 0.1f)
            {
                sb.Append(String.Format("disgust {0:F1}%, ", emotionScores.Disgust * 100));
            }
            if (emotionScores.Fear >= 0.1f)
            {
                sb.Append(String.Format("fear {0:F1}%, ", emotionScores.Fear * 100));
            }
            if (emotionScores.Happiness >= 0.1f)
            {
                sb.Append(String.Format("happiness {0:F1}%, ", emotionScores.Happiness * 100));
            }
            if (emotionScores.Neutral >= 0.1f)
            {
                sb.Append(String.Format("neutral {0:F1}%, ", emotionScores.Neutral * 100));
            }
            if (emotionScores.Sadness >= 0.1f)
            {
                sb.Append(String.Format("sadness {0:F1}%, ", emotionScores.Sadness * 100));
            }
            if (emotionScores.Surprise >= 0.1f)
            {
                sb.Append(String.Format("surprise {0:F1}%, ", emotionScores.Surprise * 100));
            }

            sb.Append(Environment.NewLine);
            // Add glasses.
            //sb.Append(face.FaceAttributes.Glasses);


            // Return the built string.
            return(sb.ToString());
        }
Ejemplo n.º 20
0
        public string ParseEmotions(EmotionScores scores)
        {
            if (scores == null)
            {
                return(null);
            }

            return(scores.ToRankedList().FirstOrDefault().Key);
        }
Ejemplo n.º 21
0
        private string obtenerEmocion(EmotionScores emotion)
        {
            string[] emocion  = { "Feliz", "Triste", "Neutral", "Sorpendido", "Enojado", "Contento", "Disgustado", "Miedoso" };
            float[]  valores  = { emotion.Happiness, emotion.Sadness, emotion.Neutral, emotion.Surprise, emotion.Anger, emotion.Contempt, emotion.Disgust, emotion.Fear };
            float    maxValue = valores.Max();
            int      indice   = valores.ToList().IndexOf(maxValue);

            return(emocion[indice]);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Calculate the highest emotion from emotion result.
        /// </summary>
        /// <param name="scores">Emotion Result</param>
        /// <returns>EmotionScoreResult which contains score and emoji to express emotion.</returns>
        private EmotionScoreResult GetHighestEmotion(EmotionScores scores)
        {
            var tempHighestEmotion      = EmotionEnum.Anger;
            var tempHighestScore        = scores.Anger;
            var tempHighestEmotionEmoji = "\U0001F621";

            if (tempHighestScore <= scores.Contempt)
            {
                tempHighestScore        = scores.Contempt;
                tempHighestEmotion      = EmotionEnum.Contempt;
                tempHighestEmotionEmoji = "\U0001F615";
            }
            if (tempHighestScore <= scores.Disgust)
            {
                tempHighestScore        = scores.Disgust;
                tempHighestEmotion      = EmotionEnum.Disgust;
                tempHighestEmotionEmoji = "\U0001F62C";
            }
            if (tempHighestScore <= scores.Fear)
            {
                tempHighestScore        = scores.Fear;
                tempHighestEmotion      = EmotionEnum.Fear;
                tempHighestEmotionEmoji = "\U0001F631";
            }
            if (tempHighestScore <= scores.Happiness)
            {
                tempHighestScore        = scores.Happiness;
                tempHighestEmotion      = EmotionEnum.Happiness;
                tempHighestEmotionEmoji = "\U0001F60D";
            }
            if (tempHighestScore <= scores.Neutral)
            {
                tempHighestScore        = scores.Neutral;
                tempHighestEmotion      = EmotionEnum.Neutral;
                tempHighestEmotionEmoji = "\U0001F610";
            }
            if (tempHighestScore <= scores.Sadness)
            {
                tempHighestScore        = scores.Sadness;
                tempHighestEmotion      = EmotionEnum.Sadness;
                tempHighestEmotionEmoji = "\U0001F622";
            }
            if (tempHighestScore <= scores.Surprise)
            {
                tempHighestScore        = scores.Surprise;
                tempHighestEmotion      = EmotionEnum.Surprise;
                tempHighestEmotionEmoji = "\U0001F632";
            }

            return(new EmotionScoreResult()
            {
                HighEmotion = tempHighestEmotion,
                HighEmotionScore = tempHighestScore,
                HighEmotionEmoji = tempHighestEmotionEmoji
            });
        }
Ejemplo n.º 23
0
        public void UpdateEmotion(EmotionScores scores)
        {
            var    topEmotion = scores.ToRankedList().First();
            string label = "", emoji = "";

            switch (topEmotion.Key)
            {
            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:
                label = "";
                emoji = "\U0001f60a";
                break;
            }

            this.emotionEmoji.Text = emoji;
            this.emotionText.Text  = label;
        }
Ejemplo n.º 24
0
        public void ShowEmotionData(EmotionScores emotion)
        {
            this.EmotionData = emotion.ToRankedList().ToArray();

            this.DataContext = this;

            this.genderAgeGrid.Visibility = Visibility.Collapsed;
            this.emotionGrid.Visibility   = Visibility.Visible;
            this.captionCanvas.Visibility = Visibility.Visible;
        }
Ejemplo n.º 25
0
 private void AssignEmotionStatistics(EmotionScores emotionScoresStatistics)
 {
     AverageAnger     = emotionScoresStatistics.Anger;
     AverageContempt  = emotionScoresStatistics.Contempt;
     AverageDisgust   = emotionScoresStatistics.Disgust;
     AverageFear      = emotionScoresStatistics.Fear;
     AverageHappiness = emotionScoresStatistics.Happiness;
     AverageNeutral   = emotionScoresStatistics.Neutral;
     AverageSadness   = emotionScoresStatistics.Sadness;
     AverageSurprise  = emotionScoresStatistics.Surprise;
 }
Ejemplo n.º 26
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;
        }
Ejemplo n.º 27
0
 private void AddAndCalculateEmotionScoresStatistics(EmotionScores emotionScores)
 {
     _angerArray.Add(emotionScores.Anger);
     _contemptArray.Add(emotionScores.Contempt);
     _disgustArray.Add(emotionScores.Disgust);
     _fearArray.Add(emotionScores.Fear);
     _happinessArray.Add(emotionScores.Happiness);
     _neutralArray.Add(emotionScores.Neutral);
     _sadnessArray.Add(emotionScores.Sadness);
     _surpriseArray.Add(emotionScores.Surprise);
 }
Ejemplo n.º 28
0
        public async Task <List <FullPersonDto> > RecognizeFullPersonsAsync(Face[] faces, string imagePath)
        {
            var selectedFaces = faces.Take(10).ToList();

            List <FullPersonDto>   persons           = new List <FullPersonDto>();
            IList <IdentifyResult> identifyResults   = new List <IdentifyResult>();
            IEnumerable <Person>   recognizedPersons = new List <Person>();

            try
            {
                identifyResults = (await _faceServiceClient.IdentifyAsync(Global.OxfordPersonGroupId, selectedFaces.Select(f => f.FaceId).ToArray())).ToList();
                IList <Guid> candidatesId = identifyResults.Where(i => i.Candidates.Any()).Select(i => i.Candidates[0].PersonId).ToList();
                recognizedPersons = _unit.PersonRepository.GetPersonsByCandidateIds(candidatesId);
            }
            catch (FaceAPIException e)
            {
                LogManager.GetLogger(GetType()).Info("Error during recognition", e);
            }

            foreach (Face face in selectedFaces)
            {
                Person         person         = null;
                IdentifyResult identifyResult = identifyResults.FirstOrDefault(i => i.FaceId == face.FaceId);

                if (identifyResult != null && identifyResult.Candidates.Any())
                {
                    person = recognizedPersons.FirstOrDefault(p => p.PersonApiId == identifyResult.Candidates[0].PersonId);
                }

                EmotionScores emotionTask = await ProcessRecognitionItemPicture(imagePath, face);

                persons.Add(new FullPersonDto
                {
                    PersonId  = face.FaceId,
                    FirstName = person.FirstName,
                    Age       = face.FaceAttributes.Age,
                    Gender    = face.FaceAttributes.Gender,
                    Beard     = face.FaceAttributes.FacialHair.Beard,
                    Glasses   = face.FaceAttributes.Glasses,
                    Mustache  = face.FaceAttributes.FacialHair.Moustache,
                    Anger     = emotionTask.Anger,
                    Contempt  = emotionTask.Contempt,
                    Disgust   = emotionTask.Disgust,
                    Fear      = emotionTask.Fear,
                    Happiness = emotionTask.Happiness,
                    Neutral   = emotionTask.Neutral,
                    Sadness   = emotionTask.Sadness,
                    Surprise  = emotionTask.Surprise
                });
            }

            return(persons);
        }
Ejemplo n.º 29
0
        private EmotionPlayer GetDominantEmotion(EmotionScores emotionScore)
        {
            //Solo aumenta el score si esta feliz!
            // var data = new EmotionPlayer() { Type = EmotionEnum.Happiness, Score = Convert.ToInt32(emotionScore.Happiness * 1000) };
            //return emotionScore.ToRankedList().Select(kv => new EmotionPlayer { Type = (EmotionEnum)Enum.Parse(typeof(EmotionEnum), kv.Key), Score = Convert.ToInt32(kv.Value) }).First();

            //--
            //var data = emotionScore.ToRankedList().Select(kv => new EmotionPlayer { Type = (EmotionEnum)Enum.Parse(typeof(EmotionEnum), kv.Key), Score = Convert.ToInt32(kv.Value * _multiplier) }).First();
            //return data;

            return(new EmotionPlayer(emotionScore));
        }
        private System.Windows.Shapes.Rectangle ComposeRectangleBarFromEmotions(EmotionScores emotionScores)
        {
            var result = new System.Windows.Shapes.Rectangle();

            var emotionRankedList       = emotionScores.ToRankedList();
            var gradientStopsCollection = new GradientStopCollection();
            var occuringEmotions        = new List <KeyValuePair <string, float> >();

            foreach (var emotion in emotionRankedList.Reverse())
            {
                if (emotion.Value > 0.0)
                {
                    occuringEmotions.Add(emotion);
                }
            }
            var occuringEmotionsCount = occuringEmotions.Count;
            var previousValue         = 0.0f;

            for (int i = 0; i < occuringEmotionsCount; i++)
            {
                var emotion      = occuringEmotions[i];
                var emotionColor = GetEmotionColor(emotion.Key);
                var emotionValue = emotion.Value;

                if (i == 0 || i == occuringEmotionsCount - 1)
                {
                    if (i == 0)
                    {
                        previousValue = emotionValue;
                    }
                    var gradientStop = new GradientStop(emotionColor, previousValue);
                    gradientStopsCollection.Add(gradientStop);
                }
                else
                {
                    var gradientStopStartPoint = new GradientStop(emotionColor, previousValue);
                    gradientStopsCollection.Add(gradientStopStartPoint);
                    previousValue += emotionValue;
                    var gradientStopEndPoint = new GradientStop(emotionColor, previousValue);
                    gradientStopsCollection.Add(gradientStopEndPoint);
                }
            }
            var linearGradientBrush = new LinearGradientBrush(gradientStopsCollection, new System.Windows.Point(0.0, 0.0), new System.Windows.Point(0.0, 1.0));
            var composedBar         = new System.Windows.Shapes.Rectangle();

            composedBar.Fill   = linearGradientBrush;
            composedBar.Width  = 5.0;
            composedBar.Margin = new Thickness(1.0, 0, 1.0, 0);
            result             = composedBar;

            return(result);
        }