页首Html代码

通道的分离与合并,ROI,

通道的分离与合并

    class Program
    {
        static void Main(String[] args)
        {
            Mat img = CvInvoke.Imread(@"C:\Users\dell\Pictures\mach.jpg");
            Mat pic = new Mat();
            int ch=img.NumberOfChannels;


            VectorOfMat dst = new VectorOfMat(ch);
            CvInvoke.Split(img,dst);
            CvInvoke.Imshow("hello", img);
            Mat blue = dst[0];
            Mat green = dst[1];
            Mat red = dst[2];

            CvInvoke.Threshold(blue, blue, 200, 255, ThresholdType.Binary);
            CvInvoke.Threshold(green, green, 200, 255, ThresholdType.Binary);
            CvInvoke.Threshold(red, red, 200, 255, ThresholdType.Binary);
            CvInvoke.Merge(dst, pic);
            
            CvInvoke.Imshow("b", blue);
            CvInvoke.Imshow("g", green);
            CvInvoke.Imshow("r", red);

            CvInvoke.Imshow("m", pic);
            CvInvoke.WaitKey(0);
        }

    }

 

效果如下:

 

 

ROI

 

    class Program
    {
        static void Main(String[] args)
        {
            Mat img = CvInvoke.Imread(@"C:\Users\dell\Pictures\mach.jpg");
            Mat logo = CvInvoke.Imread(@"C:\Users\dell\Pictures\opencv.jpg");
            Mat ROI = new Mat(img, new Rectangle(20, 20, logo.Cols, logo.Rows));
            logo.CopyTo(ROI);
            CvInvoke.Imshow("roi", img);
            CvInvoke.WaitKey(0);
        }

    }

 

 

MASK掩码

 

        static void Main(String[] args)
        {
            Mat img = CvInvoke.Imread(@"C:\Users\dell\Pictures\mach.jpg");
            Mat logo = CvInvoke.Imread(@"C:\Users\dell\Pictures\opencv.jpg");
            Mat mask = CvInvoke.Imread(@"C:\Users\dell\Pictures\opencv.jpg", 0);
            CvInvoke.BitwiseNot(mask, mask);//图像取反,白色变黑色
            CvInvoke.Imshow("mask", mask);
            CvInvoke.Threshold(mask, mask, 100, 255, ThresholdType.Binary);
            CvInvoke.Imshow("threshold", mask);
            Mat roi = new Mat(img, new Rectangle(20, 20, logo.Cols, logo.Rows));
            logo.CopyTo(roi, mask);
            CvInvoke.Imshow("img", img);
            CvInvoke.WaitKey(0);
        }

 

 

 

posted @ 2019-05-29 09:03  noigel  阅读(403)  评论(0编辑  收藏  举报
js脚本

目录导航