Example #1
0
        private void Makeup(Image <Bgr, Byte> image, Image <Gray, byte> grayImage, FaceModel faceModel, MKParams mkParams)
        {
            Graphics g = Graphics.FromImage(image.Bitmap);

            if (mkParams.SkinEnabled || mkParams.HairEnabled)
            {
                ProcessSkin(g, grayImage, image, faceModel, mkParams);
            }
            if (mkParams.LipEnabled)
            {
                ApplyLipStick(g, faceModel, mkParams);
            }
            if (mkParams.EyeLineEnabled)
            {
                ApplyEyeLinear(g, faceModel, mkParams);
            }
            if (mkParams.EyebrowEnabled)
            {
                EyeBrowEffects(g, grayImage, image, faceModel, mkParams);
            }
            if (mkParams.EyeEnabled)
            {
                ColorEyes(g, grayImage, image, faceModel, mkParams);
            }
        }
Example #2
0
        public Form1()
        {
            InitializeComponent();

            DBUtil.SetTypes();
            return;

            InitModel();
            image             = new Image <Bgr, byte>(Constants.IMAGE_PATH);
            image             = image.Resize(pictureBox1.Width, pictureBox1.Height, Inter.Linear, true);
            mainColorImage    = image.Clone();
            grayImage         = image.Convert <Gray, byte>();
            mainGrayImage     = grayImage.Clone();
            mainPicture.Image = image.ToBitmap();
            faceModel         = GetFaceModel(image, grayImage);
        }
Example #3
0
        private void ApplyLipStick(Graphics g, FaceModel faceModel, MKParams mkParams)
        {
            Point[] bottomLipPoints = faceModel.BottomLipPoints;
            Point[] topLipPoints    = faceModel.TopLipPoints;

            Point[] lipLineTop    = faceModel.LipLineTop;
            Point[] lipLineBottom = faceModel.LipLineBottom;

            //SolidBrush lipLineBrush = new SolidBrush(Color.FromArgb(mkParams.LipLineAlpha, mkParams.LipLineColor));
            //Pen lipLinePen = new Pen(lipLineBrush, 1);
            //g.DrawClosedCurve(lipLinePen, lipLineTop);
            //g.DrawClosedCurve(lipLinePen, lipLineBottom);
            SolidBrush lipStickBrush = new SolidBrush(Color.FromArgb(mkParams.LipStickAlpha, mkParams.LipStickColor));

            g.FillClosedCurve(lipStickBrush, faceModel.TopLipPoints);
            g.FillClosedCurve(lipStickBrush, faceModel.BottomLipPoints);
        }
Example #4
0
        private void ApplyEyeLinear(Graphics g, FaceModel faceModel, MKParams mkParams)
        {
            SolidBrush eyeLineBrush = new SolidBrush(Color.FromArgb(mkParams.EyeLineAlpha, mkParams.EyeLineColor));
            Pen        eyeLinePen   = new Pen(eyeLineBrush, 4);

            g.DrawCurve(eyeLinePen, faceModel.LeftEyePoints);
            double leftSlope  = faceModel.LeftEyeSlope;
            double rightSlope = faceModel.RightEyeSlope;

            leftSlope  = leftSlope * mkParams.EyeLineSlope;
            rightSlope = rightSlope * mkParams.EyeLineSlope;
            int   deltaX    = (int)((faceModel.LeftEyeTopPoint.X - faceModel.LeftEyeAnglePoint.X) / 2.5);
            int   deltaY    = (int)(leftSlope * deltaX);
            Point leftPoint = new Point((int)faceModel.LeftEyeAnglePoint.X - deltaX, (int)faceModel.LeftEyeAnglePoint.Y + deltaY);

            g.DrawLine(eyeLinePen, faceModel.LeftEyeAnglePoint, leftPoint);

            deltaY = (int)(rightSlope * deltaX);
            Point rightPoint = new Point((int)faceModel.RightEyeAnglePoint.X + deltaX, (int)faceModel.RightEyeAnglePoint.Y + deltaY);

            g.DrawLine(eyeLinePen, faceModel.RightEyeAnglePoint, rightPoint);
            g.DrawCurve(eyeLinePen, faceModel.RightEyePoints);
        }
Example #5
0
 private void EyeBrowEffects(Graphics g, Image <Gray, byte> grayImage, Image <Bgr, Byte> image, FaceModel faceModel, MKParams mkParams)
 {
     ColorEyebrow(faceModel.RightEyebrowBox, image.Bitmap, true, grayImage, mkParams);
     ColorEyebrow(faceModel.LeftEyebrowBox, image.Bitmap, false, grayImage, mkParams);
 }
Example #6
0
        private void ColorEyes(Graphics g, Image <Gray, byte> grayImage, Image <Bgr, Byte> image, FaceModel faceModel, MKParams mkParams)
        {
            grayImage.ROI = faceModel.LeftEyeBox;
            CircleF[] leftEye = CvInvoke.HoughCircles(grayImage, HoughType.Gradient, 1, (double)faceModel.LeftEyeBox.Height / 5.0, 10, (double)faceModel.LeftEyeBox.Height / 5.0, faceModel.LeftEyeBox.Height);
            grayImage.ROI = faceModel.RightEyeBox;
            CircleF[] rightEye = CvInvoke.HoughCircles(grayImage, HoughType.Gradient, 1, (double)faceModel.RightEyeBox.Height / 5.0, 10, (double)faceModel.RightEyeBox.Height / 5.0, faceModel.RightEyeBox.Height);
            grayImage.ROI = Rectangle.Empty;
            SolidBrush solidBrush = new SolidBrush(Color.FromArgb(mkParams.EyeAlpha, mkParams.EyeMaskColor));

            if (leftEye.Length > 0)
            {
                g.FillEllipse(solidBrush, faceModel.LeftEyeBox.Left + leftEye[0].Center.X - leftEye[0].Radius / 2, faceModel.LeftEyeBox.Top + leftEye[0].Center.Y - leftEye[0].Radius / 2, leftEye[0].Radius, leftEye[0].Radius);
            }
            if (rightEye.Length > 0)
            {
                g.FillEllipse(solidBrush, faceModel.RightEyeBox.Left + rightEye[0].Center.X - rightEye[0].Radius / 2, faceModel.RightEyeBox.Top + rightEye[0].Center.Y - rightEye[0].Radius / 2, rightEye[0].Radius, rightEye[0].Radius);
            }
        }
Example #7
0
        private Image <Gray, byte> ProcessSkin(Graphics g, Image <Gray, byte> grayImage, Image <Bgr, Byte> image, FaceModel faceModel, MKParams mkParams)
        {
            double[] minValues;
            double[] maxValues;
            Point[]  minLocs;
            Point[]  maxLocs;

            //int hairY = faceModel.HeadBox.Y - faceModel.HeadBox.Height / 2 + faceModel.HeadBox.Height / 4;
            //Rectangle hairBox = new Rectangle(faceModel.HeadBox.X + faceModel.HeadBox.Width / 2, hairY > 0 ? hairY : 0, faceModel.HeadBox.Width / 2, faceModel.HeadBox.Height / 2);

            image.ROI = new Rectangle(faceModel.FaceBox.X + faceModel.FaceBox.Width / 2, faceModel.FaceBox.Y + faceModel.FaceBox.Height / 4, faceModel.FaceBox.Width / 2, faceModel.FaceBox.Height / 2);
            image.MinMax(out minValues, out maxValues, out minLocs, out maxLocs);
            image.ROI = Rectangle.Empty;
            double             avg0     = (minValues[0] + maxValues[0]) * mkParams.SkinRatio;
            double             avg1     = (minValues[0] + maxValues[0]) * mkParams.SkinRatio;
            double             avg2     = (minValues[0] + maxValues[0]) * mkParams.SkinRatio;
            Image <Gray, byte> skinMask = image.InRange(new Bgr(minValues[0], minValues[1], minValues[2]), new Bgr(avg0, avg1, avg2));

            for (int i = faceModel.FaceBox.Bottom - 1; i >= faceModel.FaceBox.Top; i--)
            {
                for (int j = faceModel.FaceBox.Right - 1; j >= faceModel.FaceBox.Left; j--)
                {
                    Color oldColor = image.Bitmap.GetPixel(j, i);
                    int   oldRed   = oldColor.R;
                    int   oldGreen = oldColor.G;
                    int   oldBlue  = oldColor.B;
                    bool  inFace   = isInBox(i, j, faceModel.FaceBox);
                    if (skinMask[i, j].MCvScalar.V0 == 0 && inFace && mkParams.SkinEnabled)
                    {
                        Color maskColor = mkParams.SkinMaskColor;
                        int   maskRed   = maskColor.R;
                        int   maskGreen = maskColor.G;
                        int   maskBlue  = maskColor.B;

                        int   newRed   = (int)(mkParams.FaceAlpha * maskRed + (1 - mkParams.FaceAlpha) * oldRed);
                        int   newGreen = (int)(mkParams.FaceAlpha * maskGreen + (1 - mkParams.FaceAlpha) * oldGreen);
                        int   newBlue  = (int)(mkParams.FaceAlpha * maskBlue + (1 - mkParams.FaceAlpha) * oldBlue);
                        Color newColor = Color.FromArgb(newRed, newGreen, newBlue);
                        image.Bitmap.SetPixel(j, i, newColor);
                    }
                }
            }
            return(skinMask);
        }
Example #8
0
 public Rectangle GetBoundingBox()
 {
     return(FaceModel.getBoundingBox(GetArray()));
 }