OpenCVSharp 4.5 拉普拉斯算子

OpenCVSharp 4.5 跑一遍OpenCV官方教程(全为手敲代码,如有雷同都是我的错)

官方OpenCV教程链接:https://docs.opencv.org/4.5.0/d5/db5/tutorial_laplace_operator.html

核心函数: Laplacian() 

using System;
using OpenCvSharp;

namespace ConsoleApp1
{
    class tutorial14 : ITutorial
    {
        public void Run()
        {

            // Declare the variables we are going to use            
            int kernel_size = 3;
            int scale = 1;
            int delta = 0;
            MatType ddepth = MatType.CV_16S;

            const string window_name = "Laplace Demo";
            const string imageName = "I:\\csharp\\images\\lena.jpg";
            using (Mat src = new Mat(imageName, ImreadModes.Color))
            using (Mat src_gray = new Mat())
            using(Mat dst = new Mat())
            {
                // Reduce noise by blurring with a Gaussian filter ( kernel size = 3 )
                Cv2.GaussianBlur(src, src, new Size(3, 3), 0, 0, BorderTypes.Default);
                Cv2.CvtColor(src, src_gray, ColorConversionCodes.BGR2GRAY); // Convert the image to grayscale
                Mat abs_dst = new Mat();
                Cv2.Laplacian(src_gray, dst, ddepth, kernel_size, scale, delta, BorderTypes.Default);
                // converting back to CV_8U
                Cv2.ConvertScaleAbs(dst, abs_dst);
                Cv2.ImShow(window_name, abs_dst);
                Cv2.WaitKey(0);
            }
        }
    }
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值