Esempio n. 1
0
        /// <summary>
        /// Calculates a score for how similar the subject is to the target
        /// </summary>
        public double ScoreFaceDifferences(IFaceModelTargetFace subject, IFaceModelTargetFace target)
        {
            double score = 0;
            var    shc   = subject.HairColor;
            var    ssc   = subject.SkinColor;
            var    thc   = target.HairColor;
            var    tsc   = target.SkinColor;

            var hairColorDistance = Math.Sqrt(Math.Pow(shc.R - thc.R, 2) + Math.Pow(shc.G - thc.G, 2) + Math.Pow(shc.B - thc.B, 2));
            var skinColorDistance = Math.Sqrt(Math.Pow(ssc.R - tsc.R, 2) + Math.Pow(ssc.G - tsc.G, 2) + Math.Pow(ssc.B - tsc.B, 2));

            // add up to 5 points for hair/skin color differences
            score += Math.Min(5, hairColorDistance / 10);
            score += Math.Min(5, skinColorDistance / 10);

            foreach (FaceShapeDeformations deformation in Enum.GetValues(typeof(FaceShapeDeformations)))
            {
                if (!subject.Deformations.ContainsKey(deformation) || !target.Deformations.ContainsKey(deformation))
                {
                    continue;
                }

                var deformationDifference = Math.Abs(subject.Deformations[deformation] - target.Deformations[deformation]);
                score += deformationDifference;
            }

            return(score);
        }
        /// <summary>
        /// Calculates a score for how similar the subject is to the target
        /// </summary>
        public double ScoreFaceDifferences(IFaceModelTargetFace subject, IFaceModelTargetFace target)
        {
            double score = 0;
            var shc = subject.HairColor;
            var ssc = subject.SkinColor;
            var thc = target.HairColor;
            var tsc = target.SkinColor;

            var hairColorDistance = Math.Sqrt(Math.Pow(shc.R - thc.R, 2) + Math.Pow(shc.G - thc.G, 2) + Math.Pow(shc.B - thc.B, 2));
            var skinColorDistance = Math.Sqrt(Math.Pow(ssc.R - tsc.R, 2) + Math.Pow(ssc.G - tsc.G, 2) + Math.Pow(ssc.B - tsc.B, 2));

            // add up to 5 points for hair/skin color differences
            score += Math.Min(5, hairColorDistance / 10);
            score += Math.Min(5, skinColorDistance / 10);

            foreach (FaceShapeDeformations deformation in Enum.GetValues(typeof(FaceShapeDeformations)))
            {
                if (!subject.Deformations.ContainsKey(deformation) || !target.Deformations.ContainsKey(deformation))
                    continue;

                var deformationDifference = Math.Abs(subject.Deformations[deformation] - target.Deformations[deformation]);
                score += deformationDifference;
            }

            return score;
        }