Canny() function with Aperture_size
This is an optional parameter that is used to specify the order of the Sobel filter used to calculate the gradient in the Canny algorithm. The default value is 3 and its value should be odd between 3 and 7. You can increase the Aperture size when you want to detect more detailed features.
Python3
import cv2 img = cv2.imread( "test.jpeg" ) # Read image # Setting All parameters t_lower = 100 # Lower Threshold t_upper = 200 # Upper threshold aperture_size = 5 # Aperture size # Applying the Canny Edge filter # with Custom Aperture Size edge = cv2.Canny(img, t_lower, t_upper, apertureSize = aperture_size) 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.