Theory: In the second derivative, the value at the maximum change is zero, that is, the edge is zero. Through second-order derivative calculation, according to this theory, we can calculate the second-order derivative of the image and extract the edge.
API
public static void Laplacian(InputArray src, OutputArray dst, MatType ddepth, int ksize = 1, double scale = 1, double delta = 0, BorderTypes borderType = BorderTypes.Reflect101);
Demo:
if (fileDialog.ShowDialog() == DialogResult.OK)
{
picFile = fileDialog.FileName;
inputMat = Cv2.ImRead(picFile, ImreadModes.Grayscale);
outMat = new Mat(new Size(inputMat.Cols, inputMat.Rows), inputMat.Type());
Cv2.Laplacian(inputMat, outMat, MatType.CV_8UC1);
picBox_Display.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(inputMat);
picBox_After.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(outMat);
}
Additional notes:
The OpenCV library used in .NET in this case is OpenCvSharp4