当前位置: 首页>>代码示例>>C#>>正文


C# Mat.Resize方法代码示例

本文整理汇总了C#中OpenCvSharp.Mat.Resize方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.Resize方法的具体用法?C# Mat.Resize怎么用?C# Mat.Resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenCvSharp.Mat的用法示例。


在下文中一共展示了Mat.Resize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public void Run()
        {
            Mat src = new Mat(FilePath.Image.Girl, ImreadModes.Color);
            Mat dst = new Mat(FilePath.Image.Lenna, ImreadModes.Color);
            Mat src0 = src.Resize(dst.Size(), 0, 0, InterpolationFlags.Lanczos4);
            Mat mask = Mat.Zeros(src0.Size(), MatType.CV_8UC3);

            mask.Circle(200, 200, 100, Scalar.White, -1);

            Mat blend1 = new Mat();
            Mat blend2 = new Mat();
            Mat blend3 = new Mat();
            Cv2.SeamlessClone(
                src0, dst, mask, new Point(260, 270), blend1,
                SeamlessCloneMethods.NormalClone);
            Cv2.SeamlessClone(
                src0, dst, mask, new Point(260, 270), blend2,
                SeamlessCloneMethods.MonochromeTransfer);
                        Cv2.SeamlessClone(
                src0, dst, mask, new Point(260, 270), blend3,
                SeamlessCloneMethods.MixedClone);

            using (new Window("src", src0))
            using (new Window("dst", dst))
            using (new Window("mask", mask))
            using (new Window("blend NormalClone", blend1))
            using (new Window("blend MonochromeTransfer", blend2))
            using (new Window("blend MixedClone", blend3))
            {
                Cv2.WaitKey();
            }
        }
开发者ID:JiphuTzu,项目名称:opencvsharp,代码行数:32,代码来源:SeamlessClone.cs

示例2: PutEllipseEyeMaskOnFace

        /// <summary>
        /// Eye見て傾き検出
        /// </summary>
        /// <param name="srcMat"></param>
        /// <param name="putMat"></param>
        /// <returns></returns>
        public Mat PutEllipseEyeMaskOnFace(Mat srcMat, Mat putMat)
        {
            var grayMat = new Mat();
            Cv2.CvtColor(srcMat, grayMat, ColorConversionCodes.BGR2GRAY);
            Cv2.EqualizeHist(grayMat, grayMat);

            var faces = Cascade.DetectMultiScale(grayMat);

            if (faces == null) return srcMat;

            var polygons = new List<List<Point>>();

            var faceCount = faces.Count(); // O(n)

            for (int d = 0; d < faceCount; d++)
            {
                polygons = new List<List<Point>>();

                int x1 = faces[d].X;
                int y1 = faces[d].Y;
                int width = faces[d].Width;
                int height = faces[d].Height;
                int x2 = x1 + width;
                int y2 = y1 + height;
                int pwidth = putMat.Width;
                int pheight = putMat.Height;
                int srcWidth = srcMat.Width;
                int srcHeight = srcMat.Height;

                polygons.Add(new List<Point>() {
                new Point(x1,y1),
                new Point(x2,y1),
                new Point(x2,y2),
                new Point(x1,y2),
                });

                var faceSize = new Size(width, height);

                //重ねるファイルは少し拡大したほうが良いかな?
                /*                Mat put0 = putMat[(int)(pwidth * 0.1) ,
                                    (int)(pwidth * 0.9),
                                    (int)(pheight * 0.1),
                                    (int)(pheight * 0.9)]
                                    .Resize(new Size(width, heigh), 0, 0, InterpolationFlags.Lanczos4);
                */
                Mat put0 = putMat.Resize(faceSize, 0, 0, InterpolationFlags.Lanczos4);

                //真ん中編の色を適当に抽出
                // 改良の余地あり(肌色領域の平均取ったり?)
                MatOfByte3 mat3 = new MatOfByte3(put0); // cv::Mat_<cv::Vec3b>
                var indexer = mat3.GetIndexer();
                Vec3b color = indexer[(int)(put0.Width * 0.5), (int)(put0.Height * 0.5)];

                //抽出した色で埋める
                Mat put1 = new Mat(srcMat.Size(), MatType.CV_8UC3, new Scalar(color.Item0, color.Item1, color.Item2));

                //重ねる範囲にコピー
                put1[y1, y2, x1, x2] = put0;

                Mat put1gray = Mat.Zeros(srcMat.Size(), MatType.CV_8UC1);
                put1gray[y1, y2, x1, x2] = grayMat[y1, y2, x1, x2];
                var eyes = EyeCascade.DetectMultiScale(put1gray);
                /*
                                Debug.WriteLine(eyes.Count());

                                var cccc = new Point(eyes[0].X + eyes[0].Width * 0.5, eyes[0].Y + eyes[0].Height * 0.5);
                                put1gray.Circle(cccc,(int)(eyes[0].Width * 0.5), new Scalar(0, 255, 255));
                                return put1gray;*/
                var eyeCount = eyes.Count();
                if (eyeCount >= 2)
                {
                    var eyePpints = new List<Point>();

                    var orderedEyes = eyes.OrderByDescending(x => x.Width * x.Height).ToArray();

                    while (true)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            eyePpints.Add(new Point(eyes[i].X + eyes[i].Width * 0.5, eyes[i].Y + eyes[i].Height * 0.5));
                        }
                        var wrapRect = Cv2.MinAreaRect(eyePpints);
                        if (Math.Abs(wrapRect.Angle % 180) < 20)
                        {
                            var scale = 1.0;
                            var angle = -wrapRect.Angle % 180;

                            var eyedx = (eyePpints[0].X + eyePpints[1].X) * 0.5 - wrapRect.Center.X;
                            var eyedy = (eyePpints[0].Y + eyePpints[1].Y) * 0.5 - wrapRect.Center.Y;

                            //中心はここ
                            var center = new Point(
                                (faces[d].X + faces[d].Width * 0.5) + eyedx,
                                (faces[d].Y + faces[d].Height * 0.5) + eyedy);
//.........这里部分代码省略.........
开发者ID:0V,项目名称:Face-Exchanger,代码行数:101,代码来源:TargetDetector.cs

示例3: PutMaskOnFace

        /// <summary>
        /// Poisson Image Editing
        /// </summary>
        /// <param name="srcMat">顔がある方</param>
        /// <param name="putMat">重ねる顔</param>
        /// <returns></returns>
        public Mat PutMaskOnFace(Mat srcMat, Mat putMat)
        {
            var grayMat = new Mat();
            Cv2.CvtColor(srcMat, grayMat, ColorConversionCodes.BGR2GRAY);
            Cv2.EqualizeHist(grayMat, grayMat);

            var faces = Cascade.DetectMultiScale(grayMat);

            if (faces == null) return srcMat;

            var binaryMat = new Mat();
            int blockSize = 7;
            double k = 0.15;
            double R = 32;
            Binarizer.Sauvola(grayMat, binaryMat, blockSize, k, R);
            Cv2.BitwiseNot(binaryMat, binaryMat);

            var polygons = new List<List<Point>>();

            var faceCount = faces.Count(); // O(n)

            for (int d = 0; d < faceCount; d++)
            {
                polygons = new List<List<Point>>();

                int x1 = faces[d].X;
                int y1 = faces[d].Y;
                int width = faces[d].Width;
                int heigh = faces[d].Height;
                int x2 = x1 + width;
                int y2 = y1 + heigh;

                polygons.Add(new List<Point>() {
                new Point(x1,y1),
                new Point(x2,y1),
                new Point(x2,y2),
                new Point(x1,y2),
                });

                var pwidth = putMat.Width;
                var pheight = putMat.Height;

                //重ねるファイルは少し拡大したほうが良いかな?
                /*                Mat put0 = putMat[(int)(pwidth * 0.1) ,
                                    (int)(pwidth * 0.9),
                                    (int)(pheight * 0.1),
                                    (int)(pheight * 0.9)]
                                    .Resize(new Size(width, heigh), 0, 0, InterpolationFlags.Lanczos4);
                */
                Mat put0 = putMat.Resize(new Size(width, heigh), 0, 0, InterpolationFlags.Lanczos4);

                //真ん中編の色を適当に抽出
                // 改良の余地あり(肌色領域の平均取ったり?)
                MatOfByte3 mat3 = new MatOfByte3(put0); // cv::Mat_<cv::Vec3b>
                var indexer = mat3.GetIndexer();
                Vec3b color = indexer[(int)(put0.Width * 0.5), (int)(put0.Height * 0.5)];

                //抽出した色で埋める
                Mat put1 = new Mat(srcMat.Size(), MatType.CV_8UC3, new Scalar(color.Item0, color.Item1, color.Item2));

                //重ねる範囲にコピー
                put1[y1, y2, x1, x2] = put0;

                Mat mask = Mat.Zeros(srcMat.Size(), MatType.CV_8UC3);
                Cv2.FillPoly(mask, polygons, new Scalar(255, 255, 255));

                //中心はここ
                var center = new Point(faces[d].X + faces[d].Width * 0.5, faces[d].Y + faces[d].Height * 0.5);
                Cv2.SeamlessClone(put1, srcMat, mask, center, srcMat, SeamlessCloneMethods.NormalClone);
            }
            return srcMat;
        }
开发者ID:0V,项目名称:Face-Exchanger,代码行数:78,代码来源:TargetDetector.cs

示例4: PutEllipseMaskOnFace2

        public Mat PutEllipseMaskOnFace2(Mat srcMat, Mat putMat)
        {
            var grayMat = new Mat();
            Cv2.CvtColor(srcMat, grayMat, ColorConversionCodes.BGR2GRAY);
            Cv2.EqualizeHist(grayMat, grayMat);

            var faces = Cascade.DetectMultiScale(grayMat);

            if (faces == null) return srcMat;

            var binaryMat = new Mat();
            //            binaryMat = ColorExtractor.ExtractMask(srcMat,ColorConversionCodes.BGR2HSV,ColorVariation.Skin);
            //            return binaryMat;

            int blockSize = 7;
            double k = 1.5;
            double R = 100;
            Binarizer.Sauvola(grayMat, binaryMat, blockSize, k, R);

            Cv2.BitwiseNot(binaryMat, binaryMat);
            return binaryMat;

            var polygons = new List<List<Point>>();

            var faceCount = faces.Count(); // O(n)

            for (int d = 0; d < faceCount; d++)
            {
                polygons = new List<List<Point>>();

                int x1 = faces[d].X;
                int y1 = faces[d].Y;
                int width = faces[d].Width;
                int height = faces[d].Height;
                int x2 = x1 + width;
                int y2 = y1 + height;
                int pwidth = putMat.Width;
                int pheight = putMat.Height;
                int srcWidth = srcMat.Width;
                int srcHeight = srcMat.Height;

                polygons.Add(new List<Point>() {
                new Point(x1,y1),
                new Point(x2,y1),
                new Point(x2,y2),
                new Point(x1,y2),
                });

                // f = fixed
                /*                int fx1 = (int)(x1 - width * 0.01);
                                fx1 = fx1 > 0 ? fx1 : 0;

                                int fx2 = (int)(x2 + width * 0.01);
                                fx2 = fx2 < srcWidth ? fx2 : srcWidth;

                                int fy1 = (int)(y1 - height * 0.01);
                                fy1 = fy1 > 0 ? fy1 : 0;

                                int fy2 = (int)(y2 + height * 0.01);
                                fy2 = fy2 < srcHeight ? fy2 : srcHeight;
                                */

                int fx1 = (int)(x1 + width * 0.1);

                int fx2 = (int)(x2 - width * 0.1);

                int fy1 = (int)(y1 + height * 0.1);

                int fy2 = (int)(y2 - height * 0.1);

                int fwidth = x2 - x1;
                int fheight = y2 - y1;

                var faceSize = new Size(fwidth, fheight);

                //重ねるファイルは少し拡大したほうが良いかな?
                /*                Mat put0 = putMat[(int)(pwidth * 0.1) ,
                                    (int)(pwidth * 0.9),
                                    (int)(pheight * 0.1),
                                    (int)(pheight * 0.9)]
                                    .Resize(new Size(width, heigh), 0, 0, InterpolationFlags.Lanczos4);
                */
                Mat put0 = putMat.Resize(faceSize, 0, 0, InterpolationFlags.Lanczos4);

                //真ん中編の色を適当に抽出
                // 改良の余地あり(肌色領域の平均取ったり?)
                MatOfByte3 mat3 = new MatOfByte3(put0); // cv::Mat_<cv::Vec3b>
                var indexer = mat3.GetIndexer();
                Vec3b color = indexer[(int)(put0.Width * 0.5), (int)(put0.Height * 0.5)];

                //抽出した色で埋める
                Mat put1 = new Mat(srcMat.Size(), MatType.CV_8UC3, new Scalar(color.Item0, color.Item1, color.Item2));

                //重ねる範囲にコピー
                put1[y1, y2, x1, x2] = put0;

                Mat mask = Mat.Zeros(srcMat.Size(), MatType.CV_8UC3);

                //中心はここ
                var center = new Point(faces[d].X + faces[d].Width * 0.5, faces[d].Y + faces[d].Height * 0.5);
//.........这里部分代码省略.........
开发者ID:0V,项目名称:Face-Exchanger,代码行数:101,代码来源:TargetDetector.cs


注:本文中的OpenCvSharp.Mat.Resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。