• 通道的分离与合并,ROI,


    通道的分离与合并

        class Program
        {
            static void Main(String[] args)
            {
                Mat img = CvInvoke.Imread(@"C:UsersdellPicturesmach.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:UsersdellPicturesmach.jpg");
                Mat logo = CvInvoke.Imread(@"C:UsersdellPicturesopencv.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:UsersdellPicturesmach.jpg");
                Mat logo = CvInvoke.Imread(@"C:UsersdellPicturesopencv.jpg");
                Mat mask = CvInvoke.Imread(@"C:UsersdellPicturesopencv.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);
            }

  • 相关阅读:
    第21,22章:出现次数超过一半的数字,最短摘要的生成
    String的方法
    最长公共子串
    第29章:字符串编辑距离
    字符串转换为整数
    第11章:最长公共子序列(LCS:Longest Common Subsequence)
    django开发_七牛云CNAME解析
    django开发_七牛云图片管理
    FastDFS分布式文件系统
    requests获取响应时间(elapsed)与超时(timeout)、小数四舍五入
  • 原文地址:https://www.cnblogs.com/noigel/p/10941709.html
Copyright © 2020-2023  润新知