Esempio n. 1
0
        private void ShowFaceLandmarks()
        {
            DetectedFaceViewModel face = CurrentDetectedFace?.Entity;

            if (this.showFaceLandmarksToggle.IsOn && face != null)
            {
                double scaleX = this.faceImage.RenderSize.Width / face.FaceRectangle.Width;
                double scaleY = this.faceImage.RenderSize.Height / face.FaceRectangle.Height;

                this.faceLandmarksControl.DisplayFaceLandmarks(face.FaceRectangle, face.FaceLandmarks, scaleX, scaleY);
            }
            else
            {
                this.faceLandmarksControl.HideFaceLandmarks();
            }
        }
Esempio n. 2
0
        private void UpdateResultDetails()
        {
            DetectedFaceViewModel detectedFace   = CurrentDetectedFace?.Entity;
            FaceAttributes        faceAttributes = detectedFace?.FaceAttributes;

            if (faceAttributes != null)
            {
                if (ShowAgeAndGender)
                {
                    // gender
                    this.genderTextBlock.Text = faceAttributes.Gender.HasValue ? Util.UppercaseFirst(faceAttributes.Gender.ToString()) : NoneDesc;

                    // age
                    this.ageTextBlock.Text = faceAttributes.Age.HasValue ? faceAttributes.Age.ToString() : NoneDesc;
                }

                // hair color
                this.haircolorsGridView.ItemsSource = faceAttributes.Hair?.HairColor != null && faceAttributes.Hair.HairColor.Any()
                    ? faceAttributes.Hair.HairColor.Where(x => x.Confidence >= 0.6).Select(x => new { Confidence = string.Format("({0}%)", Math.Round(x.Confidence * 100)), HairColor = x.Color.ToString() })
                    : (object)(new[] { new { HairColor = NoneDesc } });

                // facial hair
                var facialHair = new List <KeyValuePair <string, double> >()
                {
                    new KeyValuePair <string, double>("Moustache", faceAttributes.FacialHair?.Moustache ?? 0),
                    new KeyValuePair <string, double>("Beard", faceAttributes.FacialHair?.Beard ?? 0),
                    new KeyValuePair <string, double>("Sideburns", faceAttributes.FacialHair?.Sideburns ?? 0)
                };
                if (facialHair.Any(x => x.Value > 0))
                {
                    this.facialHairGridView.ItemsSource = facialHair.Select(x => new { Value = 100 * x.Value, Type = x.Key });
                    this.facialHairGridView.Visibility  = Visibility.Visible;
                    this.facialHairTextBlock.Visibility = Visibility.Collapsed;
                }
                else
                {
                    this.facialHairTextBlock.Text       = NoneDesc;
                    this.facialHairGridView.Visibility  = Visibility.Collapsed;
                    this.facialHairTextBlock.Visibility = Visibility.Visible;
                }

                // glasses
                this.glassesTextBlock.Text = faceAttributes.Glasses.HasValue && faceAttributes.Glasses != GlassesType.NoGlasses ? faceAttributes.Glasses.ToString() : NoneDesc;

                // makeup
                var makeup = new List <string>()
                {
                    faceAttributes.Makeup != null && faceAttributes.Makeup.EyeMakeup ? "Eye" : string.Empty,
                    faceAttributes.Makeup != null && faceAttributes.Makeup.LipMakeup ? "Lip" : string.Empty
                };
                this.makeupTextBlock.Text = makeup.Any(x => !string.IsNullOrEmpty(x)) ? string.Join(", ", makeup.Where(x => !string.IsNullOrEmpty(x))) : NoneDesc;

                // accessories
                this.accessoriesGridView.ItemsSource = faceAttributes.Accessories != null && faceAttributes.Accessories.Any()
                    ? faceAttributes.Accessories.Where(x => x.Confidence >= 0.6).Select(x => new { Confidence = string.Format("({0}%)", Math.Round(x.Confidence * 100)), Accessory = x.Type.ToString() })
                    : (object)(new[] { new { Accessory = NoneDesc } });


                // emotion
                var emotionList = new List <KeyValuePair <string, double> >()
                {
                    new KeyValuePair <string, double>("Anger", faceAttributes.Emotion?.Anger ?? 0),
                    new KeyValuePair <string, double>("Contempt", faceAttributes.Emotion?.Contempt ?? 0),
                    new KeyValuePair <string, double>("Disgust", faceAttributes.Emotion?.Disgust ?? 0),
                    new KeyValuePair <string, double>("Fear", faceAttributes.Emotion?.Fear ?? 0),
                    new KeyValuePair <string, double>("Happiness", faceAttributes.Emotion?.Happiness ?? 0),
                    new KeyValuePair <string, double>("Neutral", faceAttributes.Emotion?.Neutral ?? 0),
                    new KeyValuePair <string, double>("Sadness", faceAttributes.Emotion?.Sadness ?? 0),
                    new KeyValuePair <string, double>("Surprise", faceAttributes.Emotion?.Surprise ?? 0)
                };
                var    detectedEmotions    = emotionList.Where(x => x.Value > 0).Select(x => new { Value = 100 * x.Value, Type = x.Key });
                string notDetectedEmotions = string.Join(", ", emotionList.Where(x => x.Value <= 0).Select(x => x.Key));
                if (detectedEmotions.Any())
                {
                    this.detectedEmotionGridView.ItemsSource = detectedEmotions;
                    this.detectedEmotionGridView.Visibility  = Visibility.Visible;
                    this.detectedEmotionTextBlock.Visibility = Visibility.Collapsed;
                }
                else
                {
                    this.detectedEmotionTextBlock.Text       = NoneDesc;
                    this.detectedEmotionTextBlock.Visibility = Visibility.Visible;
                    this.detectedEmotionGridView.Visibility  = Visibility.Collapsed;
                }
                this.notDetectedEmotionTextBlock.Text = !string.IsNullOrEmpty(notDetectedEmotions) ? notDetectedEmotions : NoneDesc;

                // pose
                double rollAngle     = faceAttributes.HeadPose?.Roll ?? 0;
                string rollDirection = rollAngle > 0 ? "right" : "left";
                this.headTiltTextBlock.Text = rollAngle != 0 ? $"{Math.Abs(rollAngle)}° {rollDirection}" : string.Empty;
                this.headTiltControl.DrawFacePoseData(rollAngle, angleArr: new double[] { -60, -30, 0, 30, 60 });

                double pitchAngle     = faceAttributes.HeadPose?.Pitch ?? 0;
                string pitchDirection = pitchAngle > 0 ? "up" : "down";
                this.chinAngleTextBlock.Text = pitchAngle != 0 ? $"{Math.Abs(pitchAngle)}° {pitchDirection}" : string.Empty;
                this.chinAngleControl.DrawFacePoseData(pitchAngle, angleArr: new double[] { 60, 30, 0, -30, -60 });

                double yawAngle     = faceAttributes.HeadPose?.Yaw ?? 0;
                string yawDirection = yawAngle > 0 ? "right" : "left";
                this.faceRotationTextBlock.Text = yawAngle != 0 ? $"{Math.Abs(yawAngle)}° {yawDirection}" : string.Empty;
                this.faceRotationControl.DrawFacePoseData(yawAngle, angleArr: new double[] { 60, 30, 0, -30, -60 });

                // exposure
                this.expouseTextBlock.Text = faceAttributes.Exposure?.ExposureLevel != null?Util.UppercaseFirst(faceAttributes.Exposure.ExposureLevel.ToString()) : NoneDesc;

                this.expouseProgressBar.Value = faceAttributes.Exposure != null ? 100 * faceAttributes.Exposure.Value : 0;

                // blur
                this.blurTextBlock.Text = faceAttributes.Blur?.BlurLevel != null?Util.UppercaseFirst(faceAttributes.Blur.BlurLevel.ToString()) : NoneDesc;

                this.blurProgressBar.Value = faceAttributes.Blur != null ? 100 * faceAttributes.Blur.Value : 0;

                // noise
                this.noiseTextBlock.Text = faceAttributes.Noise?.NoiseLevel != null?Util.UppercaseFirst(faceAttributes.Noise.NoiseLevel.ToString()) : NoneDesc;

                this.noiseProgressBar.Value = faceAttributes.Noise != null ? 100 * faceAttributes.Noise.Value : 0;

                // occlusion
                var occlusionList = new List <string>()
                {
                    faceAttributes.Occlusion != null && faceAttributes.Occlusion.ForeheadOccluded ? "Forehead" : string.Empty,
                    faceAttributes.Occlusion != null && faceAttributes.Occlusion.EyeOccluded ? "Eye" : string.Empty,
                    faceAttributes.Occlusion != null && faceAttributes.Occlusion.MouthOccluded ? "Mouth" : string.Empty
                };
                this.occlusionTextBlock.Text = occlusionList.Any(x => !string.IsNullOrEmpty(x)) ? string.Join(", ", occlusionList.Where(x => !string.IsNullOrEmpty(x))) : NoneDesc;
            }

            ShowFaceLandmarks();
        }