• 大小: 10.16MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-30
  • 语言: C#
  • 标签: C#  EMGU  边缘检测  canny  sobel  

资源简介

本示例是《OpenCV3编程入门》中7.1.6的综合示例的C# + EMGU 3.4.1版,在这个示例程序中,分别演示了canny边缘检测、sobel边缘检测、Laplacian算子,scharr滤波器的使用。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;

namespace SyntheticExample_EdgeDetection
{
    public partial class Form1 : Form
    {
        //原始图像
        Mat g_srcImage = new Mat();

        //Canny边缘检测相关变量
        Mat g_cannyDetectedEdges = new Mat();
        int g_cannyLowThreshold = 1; //TrackBar位置参数

        //Sobel边缘检测相关变量
        Mat g_sobelGradient_X = new Mat() g_sobelGradient_Y = new Mat();
        Mat g_sobelAbsGradient_X = new Mat() g_sobelAbsGradient_Y = new Mat();
        int g_sobelKenelSize = 0; //TrackBar位置参数

        //Laplace变换相关变量
        int g_LaplaceKenelSize = 0; //TrackBar位置参数

        //Scharr滤波器相关变量
        Mat g_scharrGradient_X = new Mat() g_scharrGradient_Y = new Mat();
        Mat g_scharrAbsGradient_X = new Mat() g_scharrAbsGradient_Y = new Mat();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            //载入原图
            g_srcImage = CvInvoke.Imread(“girl3.jpg“);
            if (g_srcImage.IsEmpty)
                MessageBox.Show(“读取srcImage错误!“);

            //显示原始图
            ImageBox_srcImage.Image = g_srcImage;

            //显示效果图
            Canny();
            Sobel();
            Laplace();
            Scharr();

            //Lable文本显示
            Lable_CannyValue.Text = “阈值:“ + TrackBar_CannyValue.Value.ToString();
            Lable_SobelValue.Text = “核大小:“ + (2 * TrackBar_SobelValue.Value + 1).ToString();
            Lable_LaplaceValue.Text = “核大小:“ + (2 * TrackBar_LaplaceValue.Value + 1).ToString();
        }

        private void Form1_KeyDown(object sender KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape || e.KeyCode == Keys.Q)
            {
                MessageBox.Show(“程序退出中...“);
                Application.Exit();
            }
        }

        //Canny边缘检测的滚动条事件函数
        private void TrackBar_CannyValue_Scroll(object sender EventArgs e)
        {
            Canny();
            Lable_CannyValue.Text = “阈值:“ + TrackBar_CannyValue.Value.ToString();
        }

        //Sobel边缘检测的滚动条事件函数
        private void TrackBar_SobelValue_Scroll(object sender EventArgs e)
        {
            Sobel();
            Lable_SobelValue.Text = “核大小:“ + (2 * TrackBar_SobelValue.Value + 1).ToString();
        }

        //Laplacian转换的滚动条事件函数
        private void TrackBar_LaplaceValue_Scroll(object sender EventArgs e)
        {
            Laplace();
            Lable_LaplaceValue.Text = “核大小:“ + (2 * TrackBar_LaplaceValue.Value + 1).ToString();
        }

        //封装Canny边缘检测的函数
        void Canny()
        {
            //原图的灰度图
            Mat g_srcGrayImage = new Mat();

      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     56320  2018-09-22 22:27  SyntheticExample-EdgeDetection\.vs\SyntheticExample-EdgeDetection\v15\.suo

     文件     659456  2018-09-22 22:21  SyntheticExample-EdgeDetection\.vs\SyntheticExample-EdgeDetection\v15\sqlite3\storage.ide

     文件        189  2018-09-22 15:39  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\App.config

     文件     115200  2018-08-21 21:36  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\Emgu.CV.UI.dll

     文件     136704  2018-08-21 21:36  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\Emgu.CV.UI.pdb

     文件      34738  2018-08-21 21:36  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\Emgu.CV.UI.xml

     文件     689664  2018-08-21 21:19  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\Emgu.CV.World.dll

     文件    1973760  2018-08-21 21:19  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\Emgu.CV.World.pdb

     文件    1799948  2018-08-21 21:19  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\Emgu.CV.World.xml

     文件      50012  2018-09-22 15:40  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\girl3.jpg

     文件      31744  2018-09-22 22:21  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\SyntheticExample-EdgeDetection.exe

     文件        189  2018-09-22 15:39  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\SyntheticExample-EdgeDetection.exe.config

     文件      26112  2018-09-22 22:21  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\SyntheticExample-EdgeDetection.pdb

     文件     307200  2018-02-08 23:14  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\ZedGraph.dll

     文件    1492968  2018-02-08 23:14  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\ZedGraph.xml

     文件      10752  2018-08-21 21:36  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\zh-CN\Emgu.CV.UI.resources.dll

     文件       4096  2018-02-08 23:14  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\bin\Debug\zh-CN\ZedGraph.resources.dll

     文件   26277376  2018-09-22 15:40  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\cvextern.dll

     文件       7274  2018-09-22 22:27  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\Form1.cs

     文件      13865  2018-09-22 22:20  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\Form1.Designer.cs

     文件       5817  2018-09-22 22:20  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\Form1.resx

     文件      45431  2018-09-22 15:41  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7605  2018-09-22 15:40  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件          0  2018-09-22 22:21  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\obj\Debug\SyntheticExample-EdgeDetection.csproj.CopyComplete

     文件         42  2018-09-22 15:40  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\obj\Debug\SyntheticExample-EdgeDetection.csproj.CoreCompileInputs.cache

     文件       2747  2018-09-22 15:42  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\obj\Debug\SyntheticExample-EdgeDetection.csproj.FileListAbsolute.txt

     文件       1012  2018-09-22 22:20  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\obj\Debug\SyntheticExample-EdgeDetection.csproj.GenerateResource.Cache

     文件      19348  2018-09-22 15:42  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\obj\Debug\SyntheticExample-EdgeDetection.csprojResolveAssemblyReference.cache

     文件      31744  2018-09-22 22:21  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\obj\Debug\SyntheticExample-EdgeDetection.exe

     文件      26112  2018-09-22 22:21  SyntheticExample-EdgeDetection\SyntheticExample-EdgeDetection\obj\Debug\SyntheticExample-EdgeDetection.pdb

............此处省略30个文件信息

评论

共有 条评论