c# OpenCvSharp 过滤器 Filter2D 边缘检测

c# OpenCvSharp 过滤器 Filter2D 边缘检测

Filter2D:利用内核实现对图像的卷积运算。

using OpenCvSharp;
using OpenCvSharp.Extensions;
using DlibDotNet;
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 System.Threading;

namespace app
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Filter2D过滤器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFilter2D_Click(object sender, EventArgs e)
        {
            // 原图
            Mat src = Cv2.ImRead(@"img\five.png");
            Cv2.ImShow("原图", src);

            // 边缘检测
            double[,] k = { { -1, -1, -1 },
                             { -1, 8, -1 },
                             { -1, -1, -1 } };

            Mat kernel = Mat.FromArray(k);
            Mat dest = new Mat();
            // 过滤器
            Cv2.Filter2D(src, dest, MatType.CV_32F, kernel);

            Cv2.ImShow("dest", dest);
        }
    }
}

 

发表回复

您的电子邮箱地址不会被公开。