Canny Edge Detector

Krithika Nagi
2 min readNov 26, 2020

--

Developed in 1986 by John F. Canny, Canny Edge Detection algorithm is an algorithm of multi-stages. It identifies the key structures in an image/video by implementing 5-stage process.

The Canny edge detection algorithm mainly follows:

  1. Noise reduction
  2. Gradient calculation
  3. Non-maximum suppression
  4. Double threshold
  5. Edge Tracking by Hysteresis.

We are gonna look at its implementation with Python’s Opencv library. My input image —

Firstly import opencv library:

Since, I want a trackbar in my output window, I will be introducing a function “nothing” only because we need it as an argument in the next few lines of code

Now we create trackbars of two kinds, one named “upper” and another “lower.”

Now we read the input image, make sure to mention the path correctly,

Convert the image to grayscle using inbuilt function from cv2

Now we will run a while loop to ensure the output is displayed properly and we use the canny edge detector fucntion whose parameters are “ gray “ which the above grayscale image, and it takes two more arguments namely “x”, “y” which are the trackbar thresholds that is obtained through the slider in the output window.

By runing the code and after setting the trackbar, we get the output as shown below,

Resources:

  1. https://en.wikipedia.org/wiki/Canny_edge_detector
  2. https://m.belfasttelegraph.co.uk/life/weekend/bbdc8/38814556.ece/AUTOCROP/h400/2019-12-28_lif_55882943_I5.JPG
  3. https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_canny/py_canny.html

--

--