Canny() function with L2Gradient
It’s a boolean parameter that specifies if you want to calculate the usual gradient equation or the L2Gradient algorithm. Again, it’s an optional parameter. L2gradient is nothing my sqrt(gradient_x_square + gradient_y_square) whereas L1gradient is just abs(gradient_x) + abs(gradient_y).
Python3
import cv2 img = cv2.imread( "test.jpeg" ) # Read image t_lower = 100 # Lower Threshold t_upper = 200 # Upper threshold aperture_size = 5 # Aperture size L2Gradient = True # Boolean # Applying the Canny Edge filter with L2Gradient = True edge = cv2.Canny(img, t_lower, t_upper, L2gradient = L2Gradient ) cv2.imshow( 'original' , img) cv2.imshow( 'edge' , edge) cv2.waitKey( 0 ) cv2.destroyAllWindows() |
Output:
Python OpenCV – Canny() Function
In this article, we will see the Canny Edge filter in OpenCV. Canny() Function in OpenCV is used to detect the edges in an image.
Syntax: cv2.Canny(image, T_lower, T_upper, aperture_size, L2Gradient)
Where:
- Image: Input image to which Canny filter will be applied
- T_lower: Lower threshold value in Hysteresis Thresholding
- T_upper: Upper threshold value in Hysteresis Thresholding
- aperture_size: Aperture size of the Sobel filter.
- L2Gradient: Boolean parameter used for more precision in calculating Edge Gradient.