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


C# Mat.Cut方法代码示例

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


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

示例1: OtherOperation

        public static bool OtherOperation(System.Drawing.Rectangle frogRect)
        {
            if (false)
            {
                var mat = Cv2.GetRotationMatrix2D(new Point2f(10, 10), 45, 1);
                Console.WriteLine(mat);
                //Console.WriteLine(mat.Dims);
                Console.WriteLine(mat.Size());
                var p = new Mat(3, 1, MatType.CV_64FC1);
                p.Set<double>(0, 0, 0);
                p.Set<double>(1, 0, 0);
                p.Set<double>(2, 0, 1);
                Console.WriteLine(p);
                //var q = mat.Cross(p);
                var q = (mat * p).ToMat();
                Console.WriteLine(q);
                Console.WriteLine(q.Get<double>(0, 0));
                Console.WriteLine(q.Get<double>(1, 0));
                return true;
            }
            if (false)
            {
                var dir = "Example2/";

                var src = new Mat("0.bmp");
                var frog = src.Cut(new Rect(frogRect.X, frogRect.Y, frogRect.Width, frogRect.Height));
                frog.ImWrite(dir + "/frog.bmp");


                var frog_hsv_channels = frog.CvtColor(ColorConversion.RgbToHsv).Split();
                for (var i = 0; i < 3; ++i)
                    frog_hsv_channels[i].ImWrite(dir + string.Format("frog {0}.png", hsv_names[i]));

                frog_hsv_channels[1].Threshold(210, 255, ThresholdType.Binary).ImWrite(dir + "frog s th.png");
                return true;
            }
            if (false)
            {
                MakeImagesForArticle();

                return true;
            }
            if (false)
            {
                DetectBallsForArticle();
                return true;
            }
            if (false)
            {
                var images = Enumerable.Range(0, 3).Select(i => string.Format("{0}.bmp", i)).Select(name => LoadBitmap(name).ToImage()).ToArray();
                //var zeroImage = new int[images[0].GetLength(0), images[0].GetLength(1)];

                var diff0_1 = images[0].Diff(images[1], 0, 0, 10);
                var diff1_2 = images[1].Diff(images[2], 0, 0, 10);
                diff0_1.ToBitmap().Save("diff s 0 1.bmp");
                diff1_2.ToBitmap().Save("diff s 1 2.bmp");
                diff0_1.And(diff1_2).ToBitmap().Save("diff s.bmp");

                foreach (var t in new[] { 0, 10, 20, 50, 100 })
                {
                    for (var dy = 0; dy < 10; ++dy)
                    {
                        images[1].Diff(images[0], 0, dy, t).ToBitmap().Save(string.Format("diff 0 {0} {1}.bmp", dy, t));
                    }
                }
                //foreach (var t in new[] { 0, 10, 20, 50, 100, 150 })
                //{
                //  images[1].Diff(zeroImage, 0, 0, t).ToBitmap().Save(string.Format("diff-z {0}.bmp", t));
                //}
                return true;
            }
            return false;
        }
开发者ID:DrReiz,项目名称:DrReiz.Robo-Gamer,代码行数:73,代码来源:Zuma.cs

示例2: MakeImagesForArticle

        private static void MakeImagesForArticle()
        {
            var resizeK = 0.2;

            var dir = "Example/";

            var src = new Mat("0.bmp");
            var src_g = new Mat("0.bmp", LoadMode.GrayScale);

            var src_1 = new Mat("1.bmp");
            var src_1_g = new Mat("1.bmp", LoadMode.GrayScale);

            var background = new Mat("background.bmp");
            var background_g = new Mat("background.bmp", LoadMode.GrayScale);

            src.Resize(resizeK).ImWrite(dir + "0.png");
            src_g.Resize(resizeK).ImWrite(dir + "0 g.png");
            src_g.ThresholdStairs().Resize(resizeK).ImWrite(dir + "0 g th.png");

            var canny = new Mat();
            Cv2.Canny(src_g, canny, 50, 200);
            canny.Resize(0.5).ImWrite(dir + "0 canny.png");

            Mat[] src_channels;
            Cv2.Split(src, out src_channels);

            for (var i = 0; i < src_channels.Length; ++i)
            {
                var channels = Enumerable.Range(0, src_channels.Length).Select(j => new Mat(src_channels[0].Rows, src_channels[0].Cols, src_channels[0].Type())).ToArray();
                channels[i] = src_channels[i];
                var dst = new Mat();
                Cv2.Merge(channels, dst);
                dst.Resize(resizeK).ImWrite(dir + string.Format("0 ch{0}.png", i));
                src_channels[i].ThresholdStairs().Resize(resizeK).ImWrite(dir + string.Format("0 ch{0} th.png", i));
            }

            if (true)
            {
                src.Resize(0.4).ImWrite(dir + "0.png");
                src_1.Resize(0.4).ImWrite(dir + "1.png");
                background.Resize(0.4).ImWrite(dir + "bg.png");

                var dst_01 = new Mat();
                Cv2.Absdiff(src, src_1, dst_01);
                dst_01.Resize(resizeK).ImWrite(dir + "01.png");
                dst_01.Cut(new Rect(50, src.Height * 4 / 5 - 50, src.Width / 5, src.Height / 5)).ImWrite(dir + "01 part.png");
                dst_01.Cut(new Rect(50, src.Height * 4 / 5 - 50, src.Width / 5, src.Height / 5)).CvtColor(ColorConversion.RgbToGray).ImWrite(dir + "01 g.png");
                dst_01.CvtColor(ColorConversion.RgbToGray).ThresholdStairs().Resize(resizeK).ImWrite(dir + "01 g th.png");

                var dst_01_g = new Mat();
                Cv2.Absdiff(src_g, src_1_g, dst_01_g);
                dst_01_g.Cut(new Rect(50, src.Height * 4 / 5 - 50, src.Width / 5, src.Height / 5)).ImWrite(dir + "0g1g.png");
                dst_01_g.ThresholdStairs().Resize(resizeK).ImWrite(dir + "0g1g th.png");
            }

            if (true)
            {
                var dst_0b = new Mat();
                Cv2.Absdiff(src, background, dst_0b);
                dst_0b.Resize(0.6).ImWrite(dir + "0b.png");

                var dst_0b_g = new Mat();
                Cv2.Absdiff(src_g, background_g, dst_0b_g);
                dst_0b_g.Resize(0.3).ImWrite(dir + "0b g.png");
                dst_0b_g.ThresholdStairs().Resize(0.3).ImWrite(dir + "0b g th.png");
            }
            if (true)
            {
                var hsv_src = new Mat();
                Cv2.CvtColor(src, hsv_src, ColorConversion.RgbToHsv);


                var hsv_background = new Mat();
                Cv2.CvtColor(background, hsv_background, ColorConversion.RgbToHsv);

                var hsv_background_channels = hsv_background.Split();

                var hsv_src_channels = hsv_src.Split();

                if (true)
                {
                    var all = new Mat(src.ToIplImage(), true);
                    for (var i = 0; i < hsv_src_channels.Length; ++i)
                    {
                        hsv_src_channels[i].CvtColor(ColorConversion.GrayToRgb).CopyTo(all, new Rect(i * src.Width / 3, src.Height / 2, src.Width / 3, src.Height / 2));
                    }
                    src_g.CvtColor(ColorConversion.GrayToRgb).CopyTo(all, new Rect(src.Width / 2, 0, src.Width / 2, src.Height / 2));
                    all.Resize(0.3).ImWrite(dir + "all.png");
                }

                foreach (var pair in new[] { "h", "s", "v" }.Select((channel, index) => new { channel, index }))
                {
                    var diff = new Mat();
                    Cv2.Absdiff(hsv_src_channels[pair.index], hsv_background_channels[pair.index], diff);
                    diff.Resize(0.3).With_Title(pair.channel).ImWrite(dir + string.Format("0b {0}.png", pair.channel));
                    diff.ThresholdStairs().Resize(0.3).ImWrite(dir + string.Format("0b {0} th.png", pair.channel));

                    hsv_src_channels[pair.index].Resize(resizeK).With_Title(pair.channel).ImWrite(dir + string.Format("0 {0}.png", pair.channel));

                    foreach (var d in new[] { -100, -50, 50, 100 })
//.........这里部分代码省略.........
开发者ID:DrReiz,项目名称:DrReiz.Robo-Gamer,代码行数:101,代码来源:Zuma.cs


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