opencv
  1. opencv-canny-edge-detection

Canny Edge Detection - ( Drawing and Image Processing in OpenCV )

Heading h2

Syntax

cv2.Canny(image, threshold1, threshold2, edges=None, apertureSize=None, L2gradient=None)

Example

import cv2
import numpy as np

# read image
img = cv2.imread('image.jpg', 0)

# apply Canny edge detection
edges = cv2.Canny(img, 100, 200)

# show the images
cv2.imshow('Image', img)
cv2.imshow('Canny Edge Detection', edges)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output

The output will consist of two images - the original image and the processed Canny edge detection image.

Explanation

Canny edge detection is a popular edge detection algorithm used in computer vision and image processing. It was introduced by John F. Canny in 1986. The algorithm is multi-staged, first using a Gaussian filter to smooth the image and then applying the Sobel operator to find the gradient of the image intensity function. The gradient is then used to determine edges, which are areas where the gradient is sufficiently high.

In OpenCV, the cv2.Canny() function can be used to apply the Canny edge detection algorithm to a grayscale image. The function takes in the image, two threshold values (minimum and maximum), and several optional arguments.

In the example above, we read in an image and apply the Canny edge detection algorithm using the cv2.Canny() function. We set the minimum threshold to 100 and the maximum threshold to 200. The resulting image is then displayed using the cv2.imshow() function.

Use

Canny edge detection is a commonly used technique in image processing, especially in computer vision and object detection. It is useful in identifying the edges of objects in an image and can be used for tasks such as image segmentation, feature extraction, and object recognition.

Important Points

  • Canny edge detection is a popular edge detection algorithm used in computer vision and image processing
  • The algorithm involves smoothing the image, finding the gradient of the image intensity function, and determining edges where the gradient is sufficiently high
  • The cv2.Canny() function in OpenCV can be used to apply the Canny edge detection algorithm to a grayscale image
  • The function takes in the image, two threshold values, and several optional arguments
  • Canny edge detection is useful in tasks such as image segmentation, feature extraction, and object recognition

Summary

In conclusion, Canny edge detection is a widely used technique in computer vision and image processing. OpenCV provides the cv2.Canny() function to implement the Canny edge detection algorithm. The function takes in several parameters, including the image, two threshold values, and several optional arguments. Canny edge detection is useful in tasks such as image segmentation, feature extraction, and object recognition.

Published on: