Principle : When the pixel transition is large at the edge of the image, the first derivative of the image is obtained. The maximum derivative value is the location of the edge pixel.
Related APIs:
public static void Sobel(InputArray src, OutputArray dst, MatType ddepth, int xorder, int yorder, int ksize = 3, double scale = 1, double delta = 0, BorderTypes borderType = BorderTypes.Reflect101);
Parameter description:
When dx=0,dy=1, the y-direction contour is clearly preserved;
when dx=1,dy=0, the x-direction contour is clearly preserved;
if (fileDialog.ShowDialog() == DialogResult.OK)
{
inputMat = Cv2.ImRead(picFile, ImreadModes.Grayscale);
outMat = new Mat(new Size(inputMat.Cols, inputMat.Rows), inputMat.Type());
Cv2.Sobel(inputMat, outMat, MatType.CV_8UC1, 1, 1,5);
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