Ejemplo n.º 1
0
        public static Bitmap Process(FaceCacheModel cacheItem)
        {
            MKParams mkParams = new MKParams();

            Bgr from = new Bgr(), to = new Bgr();

            GetColorRange(new FourPoint[] { cacheItem.Model.RightCheek, cacheItem.Model.LeftCheek, cacheItem.Model.ChainArea }, cacheItem.Image, out from, out to);
            Image <Bgr, Double> con = cacheItem.Image.Convert <Bgr, Double>();

            cacheItem.Image.ROI = cacheItem.Model.HeadArea;
            Image <Gray, byte> headColorMask = cacheItem.Image.InRange(from, to);

            cacheItem.Image.ROI = Rectangle.Empty;


            Image <Gray, byte> skinMask = new Image <Gray, byte>(cacheItem.Image.Width, cacheItem.Image.Height, new Gray(0));

            skinMask.ROI = cacheItem.Model.HeadArea;
            headColorMask.CopyTo(skinMask);
            skinMask.ROI = Rectangle.Empty;

            CvInvoke.DrawContours(skinMask, GetVVP(cacheItem.Model.FaceBoundry), -1, new Bgr(Color.White).MCvScalar, -1, LineType.EightConnected);
            CvInvoke.DrawContours(skinMask, GetVVP(cacheItem.Model.LeftEyePoints), -1, new Bgr(Color.Black).MCvScalar, -1, LineType.EightConnected);
            CvInvoke.DrawContours(skinMask, GetVVP(cacheItem.Model.RightEyePoints), -1, new Bgr(Color.Black).MCvScalar, -1, LineType.EightConnected);
            CvInvoke.DrawContours(skinMask, GetVVP(cacheItem.Model.LipBoundry), -1, new Bgr(Color.Black).MCvScalar, -1, LineType.EightConnected);
            CvInvoke.DrawContours(skinMask, GetVVP(cacheItem.Model.NoseBottom), -1, new Bgr(Color.Black).MCvScalar, -1, LineType.EightConnected);
            Image <Bgr, Double> temp = new Image <Bgr, Double>(con.Width, con.Height, new Bgr(mkParams.SkinMaskColor));

            con.AccumulateWeighted(temp, mkParams.FaceAlpha, skinMask);
            con.Draw(cacheItem.Model.HeadArea, new Bgr(Color.Blue), 2);
            con.Draw(cacheItem.Model.RightCheek.GetBoundingBox(), new Bgr(Color.Red), 2);
            con.Draw(cacheItem.Model.LeftCheek.GetBoundingBox(), new Bgr(Color.Red), 2);
            return(con.Bitmap);
        }
Ejemplo n.º 2
0
        public static void test()
        {
            Image <Bgr, Byte>  image;
            Image <Gray, byte> grayImage;
            Image <Bgr, Byte>  mainColorImage;
            Image <Gray, byte> mainGrayImage;
            FaceModel          faceModel;
            MKParams           mkParams = new MKParams();

            InitModel();
            DirectoryInfo d = new DirectoryInfo(@"D:\Face\Data_Collection\Data_Collection");

            FileInfo[] Files = d.GetFiles("*.jpg");
            foreach (FileInfo file in Files)
            {
                image          = new Image <Bgr, byte>(file.FullName);
                mainColorImage = image.Clone();
                grayImage      = image.Convert <Gray, byte>();
                mainGrayImage  = grayImage.Clone();
                faceModel      = GetFaceModel(image, grayImage);

                #region Face Skin
                Bgr from = new Bgr(), to = new Bgr();
                GetColorRange(new FourPoint[] { faceModel.RightCheek, faceModel.LeftCheek, faceModel.ChainArea }, image, out from, out to);
                Image <Bgr, Double> con = image.Convert <Bgr, Double>();

                image.ROI = faceModel.HeadArea;
                Image <Gray, byte> headColorMask = image.InRange(from, to);
                image.ROI = Rectangle.Empty;


                Image <Gray, byte> skinMask = new Image <Gray, byte>(image.Width, image.Height, new Gray(0));
                skinMask.ROI = faceModel.HeadArea;
                headColorMask.CopyTo(skinMask);
                skinMask.ROI = Rectangle.Empty;

                CvInvoke.DrawContours(skinMask, GetVVP(faceModel.FaceBoundry), -1, new Bgr(Color.White).MCvScalar, -1, LineType.EightConnected);
                CvInvoke.DrawContours(skinMask, GetVVP(faceModel.LeftEyePoints), -1, new Bgr(Color.Black).MCvScalar, -1, LineType.EightConnected);
                CvInvoke.DrawContours(skinMask, GetVVP(faceModel.RightEyePoints), -1, new Bgr(Color.Black).MCvScalar, -1, LineType.EightConnected);
                CvInvoke.DrawContours(skinMask, GetVVP(faceModel.LipBoundry), -1, new Bgr(Color.Black).MCvScalar, -1, LineType.EightConnected);
                CvInvoke.DrawContours(skinMask, GetVVP(faceModel.NoseBottom), -1, new Bgr(Color.Black).MCvScalar, -1, LineType.EightConnected);
                Image <Bgr, Double> temp = new Image <Bgr, Double>(con.Width, con.Height, new Bgr(mkParams.SkinMaskColor));
                con.AccumulateWeighted(temp, mkParams.FaceAlpha, skinMask);
                con.Draw(faceModel.HeadArea, new Bgr(Color.Blue), 2);
                con.Draw(faceModel.RightCheek.GetBoundingBox(), new Bgr(Color.Red), 2);
                con.Draw(faceModel.LeftCheek.GetBoundingBox(), new Bgr(Color.Red), 2);
                #endregion

                con.FillConvexPoly(faceModel.TopLipPoints, new Bgr(mkParams.LipStickColor));
                con.FillConvexPoly(faceModel.BottomLipPoints, new Bgr(mkParams.LipStickColor));
                DrawPoints(faceModel.TopLipPoints, con);
                DrawPoints(faceModel.BottomLipPoints, con);

                con.Save("d:\\skin.jpg");
            }
        }