Search⌘ K
AI Features

Shape Detection

Understand how to detect shapes in images using OpenCV by converting images to grayscale, applying the Canny edge detection algorithm, and retrieving contours. Learn to draw contours around detected shapes to visualize the results, preparing you to apply shape detection in data collection or image processing projects.

In this lesson, we’ll learn to detect shapes. It’ll help us find different types of shapes in our image. It can be used for data collection in scientific and various other fields.

First, we need to convert our image to grayscale. Converting the image to grayscale is really important, because it helps us find the edges properly. We use the edge detection algorithm to detect edges, along with the retrieval algorithm to detect shapes:

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

Convert to a canny image

To convert an image to a Canny image, we use the cv2.Canny() function of the OpenCv ...