Adding Shapes

Learn to draw different types of shapes on an image.

What if we want to put a certain shape, such as a rectangle, around a specific portion of an image to draw the viewer’s attention? It’ll take a very long time to add those borders to a large number of images. But we have a better idea: we’ll use OpenCV to draw the required shapes on those images.

In this lesson, we’ll draw different shapes in the code widgets below.

Drawing a circle

To draw a circle, we’ll use the circle() function of the OpenCV library. We’ll have five parameters inside this function.

Note: We need to import the OpenCV library before using this function. We should also read the image as img.

  • center is the center point of the circle around which the circle will be drawn.
  • radius is the radius of the circle.
  • redColor gives a red color to the circle. It can be changed to another color with a different color code. We’ll learn about this in detail in the next chapter.
  • circleThickness is the thickness of the circle. We can use a value of -1 to fill the circle with the same color.

Get hands-on with 1400+ tech skills courses.