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);
}
}
}
}