emgucv 图像处理
2017-05-01 11:40:00 zhgl7688 阅读数 4682

Emgucv图像处理


说明:imageBox1、imageBox2、imageBox3、imageBox4为imageBox控件

感兴趣区域ROI使用

  private void button1_Click(object sender, EventArgs e)
        {
            Mat scr = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            imageBox1.Image = scr;
            Mat scr1 = new Mat(scr.Size, DepthType.Cv8U, 3);
            scr.CopyTo(scr1);//复制一个
            //感兴趣区域ROI使用//图片组合
            Mat logo = new Mat("001.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat mat_image = new Mat(scr1, new Rectangle(new Point(80, 80), logo.Size));//提取图片的ROI保存到image中
            logo.CopyTo(mat_image, null);//把Logo数据值给image,从而改变scr的ROI数据。
            imageBox2.Image = scr1;
        }

  图像线性叠加

 private void button6_Click(object sender, EventArgs e)
        {
            Mat scr = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            imageBox1.Image = scr;
 
            Mat logo = new Mat("001.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat mat_image = new Mat(scr, new Rectangle(new Point(80, 80), logo.Size));
           //图像线性叠加
            Mat result = new Mat();
            CvInvoke.AddWeighted(logo, 0.5, mat_image, 0.5, 10, result);//加权重
            result.CopyTo(mat_image, null);//把Logo数据值给image,从而改变scr的ROI数据。
            imageBox3.Image = result;
        }

白平衡

 private void button2_Click(object sender, EventArgs e)
        {
            //白平衡
            Mat scr = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat result = new Mat();
            XPhotoInvoke.BalanceWhite(scr, result, WhiteBalanceMethod.Simple, 0, 255, 255, 0);
            imageBox1.Image = scr;
            imageBox2.Image = result;
        }

实现通道分离

 private void button3_Click(object sender, EventArgs e)
        {
            //实现通道分离
            Mat scr = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            VectorOfMat vm = new VectorOfMat();
            CvInvoke.Split(scr, vm);
            var vms = vm.GetInputOutputArray();
            Mat one_channel1 = vms.GetMat(0);
            Mat one_channel2 = vms.GetMat(1);
            Mat one_channel3 = vms.GetMat(2);
            imageBox2.Image = one_channel1;
            imageBox3.Image = one_channel2;
            imageBox4.Image = one_channel3;
        }


通道合并

private void button4_Click(object sender, EventArgs e)
        {
            //通道合并
            Mat scr = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            VectorOfMat vm = new VectorOfMat();
            CvInvoke.Split(scr, vm);
            var vms = vm.GetInputOutputArray();
            Mat one_channel1 = vms.GetMat(0);
            Mat one_channel2 = vms.GetMat(1);
            Mat one_channel3 = vms.GetMat(2);

            Mat dst = new Mat();
            CvInvoke.Merge(vm, dst);
            VectorOfMat mv = new VectorOfMat();
            mv.Push(one_channel3);
            mv.Push(one_channel2);
            mv.Push(one_channel1);
            CvInvoke.Merge(mv, dst);
            imageBox2.Image = dst;
        }

混合通道

 private void button5_Click(object sender, EventArgs e)
        {
            //混合通道
            Mat scr = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat dst = new Mat(scr.Size, DepthType.Cv8U, 3);
            int[] mix = new int[] { 0, 2, 1, 1, 2, 0 };
            CvInvoke.MixChannels(scr, dst, mix);
            imageBox5.Image = dst;
        }







2017-05-01 16:33:13 zhgl7688 阅读数 3423

Emgucv图像处理

阈值Threshold

 private void button7_Click(object sender, EventArgs e)
        {
            //阈值
            Mat scr = new Mat("001.jpg", Emgu.CV.CvEnum.ImreadModes.Grayscale);
            Mat dst = new Mat();
            CvInvoke.Threshold(scr, dst, 60, 255, ThresholdType.Binary);
            Mat dst1 = new Mat();
            CvInvoke.Threshold(scr, dst1, 60, 255, ThresholdType.BinaryInv);
            Mat dst2 = new Mat();
            CvInvoke.Threshold(scr, dst2, 60, 255, ThresholdType.Otsu);
            Mat dst3 = new Mat();
            CvInvoke.Threshold(scr, dst3, 10, 255, ThresholdType.ToZero);
            Mat dst4 = new Mat();
            CvInvoke.Threshold(scr, dst4, 10, 255, ThresholdType.ToZeroInv);
            Mat dst5 = new Mat();
            CvInvoke.Threshold(scr, dst5, 60, 255, ThresholdType.Trunc);

            imageBox1.Image = scr;
            imageBox2.Image = dst;
            imageBox3.Image = dst1;
            imageBox3.Image = dst2;
            imageBox3.Image = dst3;
            imageBox3.Image = dst4;
            imageBox3.Image = dst5;
        }

局部阈值AdaptiveThreshold

private void button8_Click(object sender, EventArgs e)
        {
            //局部阈值
            Mat scr = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.Grayscale);
            Mat dst = new Mat();
            CvInvoke.AdaptiveThreshold(scr, dst, 255, AdaptiveThresholdType.GaussianC,Emgu.CV.CvEnum.ThresholdType.BinaryInv, 3, -10);
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

中值滤波MedianBlur

private void button9_Click(object sender, EventArgs e)
        {
            //中值滤波
            Mat scr = new Mat("003.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat dst = new Mat();
            CvInvoke.MedianBlur(scr, dst, 3);
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

均值滤波Blur

 private void button10_Click(object sender, EventArgs e)
        {
            //均值滤波
            Mat scr = new Mat("003.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat dst = new Mat();
            CvInvoke.Blur(scr, dst,new Size(3,3),new Point(-1,1));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

 高斯滤波GaussianBlur

 private void button11_Click(object sender, EventArgs e)
        {
            //高斯滤波
            Mat scr = new Mat("003.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat dst = new Mat();
            CvInvoke.GaussianBlur(scr, dst, new Size(3, 3),3);
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

双边滤波BilateralFilter

 private void button12_Click(object sender, EventArgs e)
        {
            //双边滤波
            Mat scr = new Mat("001.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat dst = new Mat();
            CvInvoke.BilateralFilter(scr, dst, 10,100,15);
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

方框滤波BoxFilter

private void button13_Click(object sender, EventArgs e)
        {
            //方框滤波
            Mat scr = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat dst = new Mat();
            CvInvoke.BoxFilter(scr, dst,DepthType.Cv8U,new Size(5,5),new Point(-1,-1));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

自定义滤波Filter2D

        private void button14_Click(object sender, EventArgs e)
        {
            //自定义滤波
            int[,,] data=new int[,,]{{{-1},{0},{1}},{{-2},{0},{2}},{{-1},{0},{1}}};
            Image<Gray,int> kernel=new Image<Gray,int> (data);
            Mat scr = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            Mat dst = new Mat("002.jpg", Emgu.CV.CvEnum.ImreadModes.AnyColor);
            CvInvoke.Filter2D(scr, dst,kernel, new Point(-1,-1));
           // CvInvoke.Normalize(dst, dst, 0, 255, NormType.MinMax);
            imageBox1.Image = scr;
            imageBox2.Image = dst;
            
        }

腐蚀Erode

 private void button15_Click(object sender, EventArgs e)
        {
            //腐蚀
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.Erode(scr, dst, struct_element, new Point(-1, -1), 1, BorderType.Default, new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

膨胀Dilate

private void button16_Click(object sender, EventArgs e)
        {
            //膨胀
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.Dilate(scr, dst, struct_element, new Point(-1, -1), 1, BorderType.Default, new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

闭运算,先膨胀后腐蚀MorphologyEx--MorphOp.Close

private void button17_Click(object sender, EventArgs e)
        {
            //闭运算,先膨胀后腐蚀
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.MorphologyEx(scr, dst,MorphOp.Close, struct_element, new Point(-1, -1), 3, BorderType.Default,
                new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

开运算,先膨胀后腐蚀MorphologyEx--MorphOp.Open

 private void button18_Click(object sender, EventArgs e)
        {
            //开运算,先膨胀后腐蚀
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.MorphologyEx(scr, dst, MorphOp.Open, struct_element, new Point(-1, -1), 1, BorderType.Default,
                new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

形态学梯度MorphologyEx--MorphOp.Gradient

 private void button19_Click(object sender, EventArgs e)
        {
            //形态学梯度
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.MorphologyEx(scr, dst, MorphOp.Gradient, struct_element, new Point(-1, -1),1, BorderType.Default,
                new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

高帽MorphologyEx--MorphOp.Tophat

private void button20_Click(object sender, EventArgs e)
        {
            //高帽
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.MorphologyEx(scr, dst, MorphOp.Tophat, struct_element, new Point(-1, -1), 1, BorderType.Default,
                new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }

低帽MorphologyEx--MorphOp.Blackhat

   private void button21_Click(object sender, EventArgs e)
        {
            //低帽
            Mat scr = new Mat("002.jpg", ImreadModes.AnyColor);
            Mat dst = new Mat();
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.MorphologyEx(scr, dst, MorphOp.Blackhat, struct_element, new Point(-1, -1), 1, BorderType.Default,
                new MCvScalar(0, 0, 0));
            imageBox1.Image = scr;
            imageBox2.Image = dst;
        }


2019-01-17 17:41:00 weixin_34018202 阅读数 1

        此工具是当年自己在学习Emgucv的时候,慢慢积累的,包含了常用的图像处理算法,非常适合新人学习,现放出源码,由于是以前做的,功能不全。

        当时Emgucv的学习资料非常之少,没有一本书是讲Emgucv的,大都需要参考C++的代码,OpenCV3的书籍也只有英文版的。后来有民间高手自己写了书,对初学者还是非常有帮助的。

下载地址:https://pan.baidu.com/s/10oFI8_Obv772mgk30DYaXg  提取码:dt7s

 说明: 1.识别那一块准确率不高,后期没有时间进行优化

             2.测量没有涉及

             3.关于标定,想抽个时间写篇文章复习复习,当时是花了很多时间才搞清楚的。  

 

 

源码地址:https://github.com/FreshBreezes/EmguCVTool

转载于:https://www.cnblogs.com/thebreeze/p/10316031.html

2019-01-17 17:41:00 weixin_33671935 阅读数 13

        此工具是当年自己在学习Emgucv的时候,慢慢积累的,包含了常用的图像处理算法,非常适合新人学习,现放出源码,由于是以前做的,功能不全。

        当时Emgucv的学习资料非常之少,没有一本书是讲Emgucv的,大都需要参考C++的代码,OpenCV3的书籍也只有英文版的。后来有民间高手自己写了书,对初学者还是非常有帮助的。

下载地址:https://pan.baidu.com/s/10oFI8_Obv772mgk30DYaXg  提取码:dt7s

 说明: 1.识别那一块准确率不高,后期没有时间进行优化

             2.测量没有涉及

             3.关于标定,想抽个时间写篇文章复习复习,当时是花了很多时间才搞清楚的。  

 

 

源码地址:https://github.com/FreshBreezes/EmguCVTool

转载于:https://www.cnblogs.com/thebreeze/p/10316031.html

2015-01-12 17:49:38 ssuperliang 阅读数 429

编写高效的C#图像处理程序——我的实验

http://www.cnblogs.com/xiaotie/archive/2010/03/08/1680662.html

C# 中使用OPenCV(Emgu)心得

http://www.cnblogs.com/maiye/archive/2010/06/19/1761075.html

EmguCV学习 与opencv的区别和联系

http://jingyan.baidu.com/article/a65957f4aae29024e67f9b13.html

OpenCv,EmguCv及.net之间的互动(The Interaction of OpenCv, EmguCv AND .net)

http://www.cnblogs.com/xrwang/archive/2010/01/26/TheInteractionOfOpenCv-EmguCvANDDotNet.html

Emgucv类库学习-图像处理

博文 来自: furturerock
没有更多推荐了,返回首页