Edge Detection is an image processing technique to find boundaries of objects in the image. In this tutorial, we shall learn to find edges of focused objects in an image using Canny Edge Detection Technique.
Syntax:
Following is the syntax of OpenCV Canny Edge Detection function
edges = cv2.Canny('/path/to/img', minVal, maxVal, apertureSize, L2gradient)
Where
/path/to/img (Mandatory) : File Path of the image
minVal (Mandatory) : Minimum intensity gradient
maxVal (Mandatory) : Maximum intensity gradient
apertureSize (Optional)
L2gradient (Optional) (Default Value : false) : If true, Canny() uses a much more computationally expensive equation to detect edges, which provides more accuracy at the cost of resources.
Example:
In the following example, we python.png.jpg (an RGB image) as a GREY scale image. Then Canny() function is used to detect edges for the image.
import cv2
img = cv2.imread('python.png')
edges = cv2.Canny(img,100,200)
cv2.imshow("Edge Detected Image", edges)
cv2.waitKey(0) # waits until a key is pressed
cv2.destroyAllWindows() # destroys the window showing image
Input Image is
Output Image is