OpenCV image edge extraction (4) - Canny API edge extraction (C#)

The Canny edge detection algorithm can be divided into the following 5 steps:

  1. Apply Gaussian filtering to smooth the image with the goal of removing noise
  2. Find intensity gradients of an image
  3. Apply non-maximum suppression techniques to eliminate edge false detections (which are not detected but are originally detected)
  4. Apply a dual-threshold approach to determine possible (potential) boundaries

Description of high and low thresholds:
There are still many noise points in the image after non-maximum suppression. A technique called double threshold is applied in the Canny algorithm. That is, set an upper threshold and a lower threshold (usually specified manually in opencv). If the pixels in the image are greater than the upper bound of the threshold, they are considered to be boundaries (called strong edges), and if they are less than the lower bound of the threshold, they are considered to be boundaries. It is definitely not a boundary, and the one between the two is considered a candidate (called a weak edge) and needs further processing. The image processed by double thresholding is shown below

In the figure above, strong boundaries are represented in white and weak boundaries are represented in gray.
In the figure above, strong boundaries are represented in white and weak boundaries are represented in gray
5. Use hysteresis technology to track boundaries

API

public static void Canny(InputArray src, OutputArray edges, double threshold1, double threshold2, int apertureSize = 3, bool L2gradient = false);

Parameters
Insert image description here

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.Canny(inputMat, outMat, 30, 90);
    picBox_Display.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(inputMat);
    picBox_After.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(outMat);
}

Insert image description here

Additional notes:
The OpenCV library used in .NET in this case is OpenCvSharp4

OpenCv library for .NET environment

Guess you like

Origin blog.csdn.net/weixin_40671962/article/details/127146541