c# OpenCvSharp 形态学处理 MorphologyEx 形态学梯度 Gradient

c# OpenCvSharp 形态学处理 MorphologyEx 形态学梯度 Gradient

形态学梯度运算是用图像的膨胀图像减腐蚀图像的操作,该操作可以获取原始图像中前景图像的边缘。

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>
        /// 形态性梯度
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGrade_Click(object sender, EventArgs e)
        {

            Mat src = Cv2.ImRead(@"img\star.png");
            Cv2.ImShow("原图", src);

            Mat element = new Mat(5, 5, MatType.CV_8U, new Scalar(1));

            Mat grade = new Mat();

            Cv2.MorphologyEx(src, grade, MorphTypes.Gradient, element);

            Cv2.ImShow("形态性梯度", grade);
        }

    }
}

 

发表回复

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