Contour Detection

Learn to detect different types of shapes.

We'll cover the following...

In this lesson, we’ll learn to detect contours, which will help us find different types of shapes in our image. This can be used for motion detection, object detection, and background removal, among other things.

First, we need to convert our image to grayscale. This is really important because it helps us correctly find the edges. It also helps in simplifying algorithms and eliminates the complexity of the computational requirements. We use the edge detection algorithm to detect edges and the retrieval algorithm to detect shapes.

cv::cvtColor(img, src_gray, COLOR_BGR2GRAY);

To convert an image to a Canny image, we use the Canny() function of the OpenCV library. This function requires four parameters:

  • The first parameter is the input image.
...