c# OpenCvSharp 边缘检测 Scharr 算子

c# OpenCvSharp 边缘检测 Scharr 算子

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>
        /// Scharr算子
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnScharr_Click(object sender, EventArgs e)
        {
            // 加载图像
            Mat src = Cv2.ImRead(@"img\jiang.png");
            Cv2.ImShow("原图", src);

            Mat grad_x = new Mat();
            Mat abs_grad_x = new Mat();
            Cv2.Scharr(src, grad_x, MatType.CV_16S, 1, 0, 1, 0, BorderTypes.Default);
            Cv2.ConvertScaleAbs(grad_x, abs_grad_x);
            Cv2.ImShow("Scharr算子 X", abs_grad_x);

            Mat grad_y = new Mat();
            Mat abs_grad_y = new Mat();
            Mat dst = new Mat();
            Cv2.Scharr(src, grad_y, MatType.CV_16S, 0, 1, 1, 0, BorderTypes.Default);
            Cv2.ConvertScaleAbs(grad_y, abs_grad_y);
            Cv2.ImShow("Scharr算子 Y", abs_grad_y);

            // 水平、垂直两个方向叠加的边缘信息
            Mat grad_xy = new Mat();
            Cv2.AddWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad_xy);
            Cv2.ImShow("Scharr算子 X + Y", grad_xy);

        }

    }
}

 

发表回复

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