예제 #1
0
        public static BitmapSource DrawFaces(BitmapSource baseImage, FaceAPI.Models.DetectedFace[] faces, string[] celebName)
        {
            if (faces == null)
            {
                return(baseImage);
            }

            Action <DrawingContext, double> drawAction = (drawingContext, annotationScale) =>
            {
                for (int i = 0; i < faces.Length; i++)
                {
                    var face = faces[i];
                    if (face.FaceRectangle == null)
                    {
                        continue;
                    }

                    Rect faceRect = new Rect(
                        face.FaceRectangle.Left, face.FaceRectangle.Top,
                        face.FaceRectangle.Width, face.FaceRectangle.Height);

                    var summary = new StringBuilder();

                    if (face.FaceAttributes != null)
                    {
                        summary.Append(Aggregation.SummarizeFaceAttributes(face.FaceAttributes));
                    }

                    if (face.FaceAttributes?.Emotion != null)
                    {
                        summary.Append(Aggregation.SummarizeEmotion(face.FaceAttributes.Emotion));
                    }

                    if (celebName?[i] != null)
                    {
                        summary.Append(celebName[i]);
                    }

                    faceRect.Inflate(6 * annotationScale, 3 * annotationScale);

                    double lineThickness = 3 * annotationScale;

                    drawingContext.DrawRectangle(
                        Brushes.Transparent,
                        new Pen(s_lineBrush, lineThickness),
                        faceRect);

                    if (summary.Length > 0)
                    {
                        FormattedText ft = new FormattedText(summary.ToString(),
                                                             CultureInfo.CurrentCulture, FlowDirection.LeftToRight, s_typeface,
                                                             16 * annotationScale, Brushes.Black);

                        var pad = 3 * annotationScale;

                        var ypad   = pad;
                        var xpad   = pad + 4 * annotationScale;
                        var origin = new System.Windows.Point(
                            faceRect.Left + xpad - lineThickness / 2,
                            faceRect.Top - ft.Height - ypad + lineThickness / 2);
                        var rect = ft.BuildHighlightGeometry(origin).GetRenderBounds(null);
                        rect.Inflate(xpad, ypad);

                        drawingContext.DrawRectangle(s_lineBrush, null, rect);
                        drawingContext.DrawText(ft, origin);
                    }
                }
            };

            return(DrawOverlay(baseImage, drawAction));
        }
예제 #2
0
        public static BitmapSource DrawFaces(BitmapSource baseImage, FaceAPI.Face[] faces, ObservableCollection <Microsoft.ProjectOxford.Face.Controls.Face> targetFaces, EmotionScores[] emotionScores, string[] celebName, List <PersonData> personData, DataTable dataTable, ImageWall imageWall)
        {
            if (faces == null)
            {
                return(baseImage);
            }

            Action <DrawingContext, BitmapSource, double> drawAction = (drawingContext, oriImage, annotationScale) =>
            {
                for (int i = 0; i < faces.Length; i++)
                {
                    if (targetFaces[i].PersonName == "Unknown")
                    {
                        continue;
                    }
                    var face = faces[i];
                    imageWall.colorful[imageWall.id.IndexOf(targetFaces[i].FaceId)] = true;
                    if (face.FaceRectangle == null)
                    {
                        continue;
                    }

                    PersonData pD = new PersonData();
                    try {
                        pD = personData.Find(x => x.ID == targetFaces[i].FaceId);
                        pD.Times++;
                    } catch (Exception) {
                        personData.Find(x => x.ID == targetFaces[i].FaceId);
                    }


                    Rect faceRect = new Rect(
                        face.FaceRectangle.Left, face.FaceRectangle.Top,
                        face.FaceRectangle.Width, face.FaceRectangle.Height);
                    Int32Rect faceRectInt32 = new Int32Rect(
                        face.FaceRectangle.Left, face.FaceRectangle.Top,
                        face.FaceRectangle.Width, face.FaceRectangle.Height);
                    string text = "";

                    drawingContext.DrawImage(new CroppedBitmap(oriImage, faceRectInt32), faceRect);

                    if (face.FaceAttributes != null)
                    {
                        text += Aggregation.SummarizeFaceAttributes(face.FaceAttributes, targetFaces[i].PersonName, pD);
                    }

                    if (emotionScores?[i] != null)
                    {
                        text += Aggregation.SummarizeEmotion(emotionScores[i]);
                    }

                    if (celebName?[i] != null)
                    {
                        text += celebName[i];
                    }

                    faceRect.Inflate(6 * annotationScale, 6 * annotationScale);

                    double lineThickness = 4 * annotationScale;

                    drawingContext.DrawRectangle(
                        Brushes.Transparent,
                        new Pen(s_lineBrush, lineThickness),
                        faceRect);

                    if (text != "")
                    {
                        FormattedText ft = new FormattedText(text,
                                                             CultureInfo.CurrentCulture, FlowDirection.LeftToRight, s_typeface,
                                                             16 * annotationScale, Brushes.Black);

                        var pad = 3 * annotationScale;

                        var ypad   = pad;
                        var xpad   = pad + 4 * annotationScale;
                        var origin = new System.Windows.Point(
                            faceRect.Left + xpad - lineThickness / 2,
                            faceRect.Top - ft.Height - ypad + lineThickness / 2);
                        var rect = ft.BuildHighlightGeometry(origin).GetRenderBounds(null);
                        rect.Inflate(xpad, ypad);

                        drawingContext.DrawRectangle(s_lineBrush, null, rect);
                        drawingContext.DrawText(ft, origin);
                    }
                }
                dataTable.dataGrid.ItemsSource = personData;
                imageWall.UpdateCanvas();
            };

            return(DrawOverlay(baseImage, drawAction));
        }
예제 #3
0
        public static string SummarizeEmotion(EmotionScores scores)
        {
            var bestEmotion = Aggregation.GetDominantEmotion(scores);

            return(string.Format("{0}: {1:N1}", bestEmotion.Item1, bestEmotion.Item2));
        }
예제 #4
0
        public static BitmapSource DrawFaces(BitmapSource baseImage, Microsoft.ProjectOxford.Face.Contract.Face[] faces, EmotionScores[] emotionScores, string[] celebName)
        {
            try
            {
                if (faces == null)
                {
                    return(baseImage);
                }

                Action <DrawingContext, double> drawAction = (drawingContext, annotationScale) =>
                {
                    for (int i = 0; i < faces.Length; i++)
                    {
                        var face = faces[i];
                        if (face.FaceRectangle == null)
                        {
                            continue;
                        }

                        Rect faceRect = new Rect(
                            face.FaceRectangle.Left, face.FaceRectangle.Top,
                            face.FaceRectangle.Width, face.FaceRectangle.Height);
                        string text = "";

                        if (face.FaceAttributes != null)
                        {
                            text += Aggregation.SummarizeFaceAttributes(face.FaceAttributes);
                        }

                        if (emotionScores?[i] != null)
                        {
                            text += Aggregation.SummarizeEmotion(emotionScores[i]);
                        }

                        if (celebName?[i] != null)
                        {
                            text += celebName[i];
                        }

                        faceRect.Inflate(6 * annotationScale, 6 * annotationScale);

                        double lineThickness = 4 * annotationScale;

                        drawingContext.DrawRectangle(
                            Brushes.Transparent,
                            new Pen(s_lineBrush, lineThickness),
                            faceRect);

                        if (text != "")
                        {
                            FormattedText ft = new FormattedText(text,
                                                                 CultureInfo.CurrentCulture, FlowDirection.LeftToRight, s_typeface,
                                                                 16 * annotationScale, Brushes.Black);

                            var pad = 3 * annotationScale;

                            var ypad   = pad;
                            var xpad   = pad + 4 * annotationScale;
                            var origin = new System.Windows.Point(
                                faceRect.Left + xpad - lineThickness / 2,
                                faceRect.Top - ft.Height - ypad + lineThickness / 2);
                            var rect = ft.BuildHighlightGeometry(origin).GetRenderBounds(null);
                            rect.Inflate(xpad, ypad);

                            drawingContext.DrawRectangle(s_lineBrush, null, rect);
                            drawingContext.DrawText(ft, origin);
                        }
                    }
                };

                return(DrawOverlay(baseImage, drawAction));
            }
            catch {
                return(null);
            }
        }
예제 #5
0
        private static string SummarizeEmotionFaceAPI(FaceAttributes attr)
        {
            var bestEmotion = Aggregation.GetDominantEmotionFaceAPI(attr);

            return(string.Format("{0}: {1:N1}%", bestEmotion.Item1, bestEmotion.Item2));
        }
예제 #6
0
        public static string SummarizeEmotion(Emotion scores)
        {
            var bestEmotion = Aggregation.GetDominantEmotion(scores);

            return(string.Format("{0}: {1:N1}", bestEmotion.Key, bestEmotion.Value));
        }
예제 #7
0
        public static string SummarizeEmotion(Microsoft.ProjectOxford.Common.Contract.EmotionScores scores)
        {
            var bestEmotion = Aggregation.GetDominantEmotion(scores);

            return(string.Format("{0}: {1}%", bestEmotion.Item1, (int)(bestEmotion.Item2 * 100)));
        }
예제 #8
0
        internal static TextBlock SummarizeAllAttributes(TextBlock tb, FaceAPI.Face[] faces, AtosEmployee[] celebrityNames, Tag[] tags, EmotionScores[] emotionScores)
        {
            tb.Inlines.Clear();
            var header = "Hi!";

            if (celebrityNames != null && celebrityNames.Length > 0)
            {
                header = "Hi, " + celebrityNames[0].FirstName + " " + celebrityNames[0].LastName;

                tb.Inlines.Add(new Run(header)
                {
                    FontSize = 24
                });

                tb.Inlines.Add(new LineBreak());
                tb.Inlines.Add(String.Format("Your email is {0}", celebrityNames[0].Email));

                if (_latestEmail != celebrityNames[0].Email)
                {
                    _latestEmail = celebrityNames[0].Email;
                    list         = ExchangeManipulator.ExchangeHandler.GetCalendarInfo(celebrityNames[0].Email);
                }
                tb.Inlines.Add(new LineBreak());
                tb.Inlines.Add(new LineBreak());
                tb.Inlines.Add(String.Format("You next meetings are:"));
                foreach (var item in list)
                {
                    tb.Inlines.Add(new LineBreak());
                    tb.Inlines.Add(String.Format("{0} from {1} to {2}", item.Status, item.StartDate.ToShortTimeString(), item.EndDate.ToShortTimeString()));
                }
            }
            else
            {
                header = "Who the duck are you?";
                tb.Inlines.Add(new Run(header)
                {
                    FontSize = 24
                });
            }

            if (faces != null && faces.Length > 0)
            {
                var face = faces[0];
                if (face.FaceAttributes != null)
                {
                    tb.Inlines.Add(new LineBreak());
                    var gender = face.FaceAttributes.Gender;
                    tb.Inlines.Add(String.Format("You are {0}", gender));

                    tb.Inlines.Add(new LineBreak());
                    var age = face.FaceAttributes.Age;
                    tb.Inlines.Add(String.Format("I think you are {0} years old", age));

                    tb.Inlines.Add(new LineBreak());
                    var facialHair = face.FaceAttributes.FacialHair;
                    if (facialHair.Beard > 0.5)
                    {
                        tb.Inlines.Add(new LineBreak());
                        tb.Inlines.Add(String.Format("I think I see a beard ({0}%)", facialHair.Beard * 100));
                    }
                    if (facialHair.Moustache > 0.5)
                    {
                        tb.Inlines.Add(new LineBreak());
                        tb.Inlines.Add(String.Format("I think I see a moustache ({0}%)", facialHair.Moustache * 100));
                    }
                    if (facialHair.Sideburns > 0.5)
                    {
                        tb.Inlines.Add(new LineBreak());
                        tb.Inlines.Add(String.Format("Do I see sideburns? ({0}%)", facialHair.Sideburns * 100));
                    }

                    var makeUp = face.FaceAttributes.Makeup;
                    if (makeUp.EyeMakeup)
                    {
                        tb.Inlines.Add(new LineBreak());
                        tb.Inlines.Add(String.Format("I think I see some eye makeup"));
                    }
                    if (makeUp.LipMakeup)
                    {
                        tb.Inlines.Add(new LineBreak());
                        tb.Inlines.Add(String.Format("I think I see a lipstick"));
                    }

                    tb.Inlines.Add(new LineBreak());
                    var hair = face.FaceAttributes.Hair;
                    if (hair.Bald > 0.5)
                    {
                        tb.Inlines.Add(new LineBreak());
                        tb.Inlines.Add(String.Format("I think you're bald ({0}%)", hair.Bald * 100));
                    }
                    else
                    {
                        if (hair.HairColor.Count() > 0)
                        {
                            tb.Inlines.Add(new LineBreak());
                            tb.Inlines.Add(String.Format("Your hair color is {0}", hair.HairColor[0].Color.ToString()));
                        }
                    }

                    var glasses     = face.FaceAttributes.Glasses;
                    var glassesText = "";
                    switch (glasses)
                    {
                    case FaceAPI.Glasses.NoGlasses: glassesText = "no glasses"; break;

                    case FaceAPI.Glasses.ReadingGlasses: glassesText = "reading glasses"; break;

                    case FaceAPI.Glasses.Sunglasses: glassesText = "sunglasses"; break;

                    case FaceAPI.Glasses.SwimmingGoggles: glassesText = "swimming goggles"; break;
                    }
                    tb.Inlines.Add(new LineBreak());
                    tb.Inlines.Add(String.Format("Your are wearing {0}", glassesText));

                    var smile = face.FaceAttributes.Smile;
                    if (smile > 0.5)
                    {
                        tb.Inlines.Add(new LineBreak());
                        tb.Inlines.Add(String.Format("I see a smile! ({0}%)", smile * 100));
                    }


                    if (face.FaceAttributes.Emotion != null)
                    {
                        tb.Inlines.Add(new LineBreak());
                        var emotion     = Aggregation.SummarizeEmotion(face.FaceAttributes.Emotion);
                        var emotionPair = Aggregation.GetDominantEmotion(face.FaceAttributes.Emotion);
                        tb.Inlines.Add(String.Format("You major emotion is "));
                        switch (emotionPair.Item1)
                        {
                        case "Anger": tb.Inlines.Add(new Run(emotion)
                            {
                                Foreground = Brushes.Red
                            }); break;

                        case "Happiness": tb.Inlines.Add(new Run(emotion)
                            {
                                Foreground = Brushes.Green
                            }); break;

                        case "Sadness": tb.Inlines.Add(new Run(emotion)
                            {
                                Foreground = Brushes.Blue
                            }); break;

                        case "Surprise": tb.Inlines.Add(new Run(emotion)
                            {
                                Foreground = Brushes.Orange
                            }); break;

                        case "Disgust": tb.Inlines.Add(new Run(emotion)
                            {
                                Foreground = Brushes.Brown
                            }); break;

                        case "Fear": tb.Inlines.Add(new Run(emotion)
                            {
                                Foreground = Brushes.Gray
                            }); break;

                        default: tb.Inlines.Add(new Run(emotion)
                            {
                                Foreground = Brushes.Black
                            }); break;
                        }
                    }
                }
            }
            //tb.Inlines.Add(new Run("the TextBlock control ") { FontWeight = FontWeights.Bold });
            //tb.Inlines.Add("using ");
            //tb.Inlines.Add(new Run("inline ") { FontStyle = FontStyles.Italic });
            //tb.Inlines.Add(new Run("text formatting ") { Foreground = Brushes.Blue });
            //tb.Inlines.Add("from ");
            //tb.Inlines.Add(new Run("Code-Behind") { TextDecorations = TextDecorations.Underline });
            //tb.Inlines.Add(".");
            //List<string> attrs = new List<string>();
            //if (attr.Gender != null) attrs.Add(attr.Gender);
            //if (attr.Age > 0) attrs.Add(attr.Age.ToString());
            //if (attr.HeadPose != null)
            //{
            //    // Simple rule to estimate whether person is facing camera.
            //    bool facing = Math.Abs(attr.HeadPose.Yaw) < 25;
            //    attrs.Add(facing ? "facing camera" : "not facing camera");
            //}
            ////if (attr.FacialHair != null) attrs.Add("Your beard score: " + attr.FacialHair.Beard);
            return(tb);
        }
예제 #9
0
        public static BitmapSource DrawFaces(BitmapSource baseImage, IRound round, Dictionary <Guid, Microsoft.ProjectOxford.Face.Contract.Face> identities, ScoringSystem scoring, MainWindow.AppMode mode)
        {
            if (identities == null)
            {
                return(baseImage);
            }

            Action <DrawingContext, double> drawAction = (drawingContext, annotationScale) =>
            {
                foreach (var personId in identities.Keys)
                {
                    var face = identities[personId];

                    if (face.FaceRectangle == null)
                    {
                        continue;
                    }

                    Rect faceRect = new Rect(
                        face.FaceRectangle.Left, face.FaceRectangle.Top,
                        face.FaceRectangle.Width, face.FaceRectangle.Height);
                    string text = "";

                    SolidColorBrush brush;
                    if (!colorsForPlayers.TryGetValue(personId, out brush))
                    {
                        colorsForPlayers[personId] = GetLatestBrush();
                    }
                    brush = colorsForPlayers[personId];

                    if (face.FaceAttributes != null && mode == MainWindow.AppMode.Faces)
                    {
                        text += Aggregation.SummarizeFaceAttributes(face.FaceAttributes);
                    }

                    if (face.FaceAttributes.Emotion != null && mode == MainWindow.AppMode.Emotions)
                    {
                        text += Aggregation.SummarizeEmotion(face.FaceAttributes.Emotion);
                    }

                    if (scoring.CurrentRoundScore.ContainsKey(personId))
                    {
                        text += string.Format("  +{0}pts", scoring.CurrentRoundScore[personId]);
                    }

                    faceRect.Inflate(6 * annotationScale, 6 * annotationScale);

                    double lineThickness = 4 * annotationScale;

                    drawingContext.DrawRectangle(
                        Brushes.Transparent,
                        new Pen(brush, lineThickness),
                        faceRect);


                    //drawingContext.DrawImage(ImageProvider.Frame, faceRect);

                    if (text != "")
                    {
                        FormattedText ft = new FormattedText(text,
                                                             CultureInfo.CurrentCulture, FlowDirection.LeftToRight, s_typeface,
                                                             16 * annotationScale, Brushes.Black);

                        var pad = 3 * annotationScale;

                        var ypad   = pad;
                        var xpad   = pad + 4 * annotationScale;
                        var origin = new System.Windows.Point(
                            faceRect.Left + xpad - lineThickness / 2,
                            faceRect.Top - ft.Height - ypad + lineThickness / 2);
                        var rect = ft.BuildHighlightGeometry(origin).GetRenderBounds(null);
                        rect.Inflate(xpad, ypad);

                        drawingContext.DrawRectangle(brush, null, rect);
                        drawingContext.DrawText(ft, origin);
                    }
                }
            };

            return(DrawOverlay(baseImage, drawAction, true));
        }