Ejemplo n.º 1
0
        public virtual List <string> Morph(string fileName1, string fileName2, string outputFolder, double p)
        {
            List <string> results = new List <string>()
            {
                outputFolder + "resul1.jpg", outputFolder + "resul2.jpg", outputFolder + "resul3.jpg"
            };

            FaceRectangle[] srcARect, srcBRect;
            FaceLandmarks[] srcALandmarks, srcBLandmarks;
            string          srcAFile = fileName1;
            string          srcBFile = fileName2;

            runFaceAPI(srcAFile, out srcARect, out srcALandmarks);
            runFaceAPI(srcBFile, out srcBRect, out srcBLandmarks);

            PointF[] srcALandmarkArr = convertLandmarkFormation(ref srcALandmarks[0], ref srcARect[0]);
            PointF[] srcBLandmarkArr = convertLandmarkFormation(ref srcBLandmarks[0], ref srcBRect[0]);

            Rectangle srcARectangle = convertRectangleFormation(srcARect[0], srcAFile);
            Rectangle srcBRectangle = convertRectangleFormation(srcBRect[0], srcBFile);

            Image <Bgr, byte> srcAFaceOriginal = new Image <Bgr, byte>(srcAFile);
            Image <Bgr, byte> srcBFaceOriginal = new Image <Bgr, byte>(srcBFile);

            Image <Bgr, byte> srcAFace = srcAFaceOriginal.GetSubRect(srcARectangle);
            Image <Bgr, byte> srcBFace = srcBFaceOriginal.GetSubRect(srcBRectangle);

            FaceIntegration faceIntegration = new FaceIntegration(
                srcAFace,
                srcBFace,
                srcALandmarkArr,
                srcBLandmarkArr,
                new Size(300, 300),
                p);
            Image <Bgr, byte> dstFace = faceIntegration.integrateFace();

            CvInvoke.MedianBlur(dstFace, dstFace, 5);

            dstFace.Save(results[0]);

            dstFace.Resize(srcARectangle.Width, srcARectangle.Height, Emgu.CV.CvEnum.Inter.Linear).CopyTo(srcAFace);
            srcAFaceOriginal.Save(results[1]);
            dstFace.Resize(srcBRectangle.Width, srcBRectangle.Height, Emgu.CV.CvEnum.Inter.Linear).CopyTo(srcBFace);
            srcBFaceOriginal.Save(results[2]);
            return(results);
        }
Ejemplo n.º 2
0
        public virtual List<string> Morph(string fileName1, string fileName2, string outputFolder, double p)
        {
            List<string> results = new List<string>() { outputFolder + "resul1.jpg", outputFolder + "resul2.jpg", outputFolder + "resul3.jpg" };

            FaceRectangle[] srcARect, srcBRect;
            FaceLandmarks[] srcALandmarks, srcBLandmarks;
            string srcAFile = fileName1;
            string srcBFile = fileName2;

            runFaceAPI(srcAFile, out srcARect, out srcALandmarks);
            runFaceAPI(srcBFile, out srcBRect, out srcBLandmarks);

            PointF[] srcALandmarkArr = convertLandmarkFormation(ref srcALandmarks[0], ref srcARect[0]);
            PointF[] srcBLandmarkArr = convertLandmarkFormation(ref srcBLandmarks[0], ref srcBRect[0]);

            Rectangle srcARectangle = convertRectangleFormation(srcARect[0], srcAFile);
            Rectangle srcBRectangle = convertRectangleFormation(srcBRect[0], srcBFile);

            Image<Bgr, byte> srcAFaceOriginal = new Image<Bgr, byte>(srcAFile);
            Image<Bgr, byte> srcBFaceOriginal = new Image<Bgr, byte>(srcBFile);

            Image<Bgr, byte> srcAFace = srcAFaceOriginal.GetSubRect(srcARectangle);
            Image<Bgr, byte> srcBFace = srcBFaceOriginal.GetSubRect(srcBRectangle);

            FaceIntegration faceIntegration = new FaceIntegration(
                srcAFace,
                srcBFace,
                srcALandmarkArr,
                srcBLandmarkArr,
                new Size(300, 300),
                p);
            Image<Bgr, byte> dstFace = faceIntegration.integrateFace();
            CvInvoke.MedianBlur(dstFace, dstFace, 5);

            dstFace.Save(results[0]);

            dstFace.Resize(srcARectangle.Width, srcARectangle.Height, Emgu.CV.CvEnum.Inter.Linear).CopyTo(srcAFace);
            srcAFaceOriginal.Save(results[1]);
            dstFace.Resize(srcBRectangle.Width, srcBRectangle.Height, Emgu.CV.CvEnum.Inter.Linear).CopyTo(srcBFace);
            srcBFaceOriginal.Save(results[2]);
            return results;
        }