Python OpenCV Drawing Shapes

In this Python OpenCV lesson we are going to learn Python OpenCV Drawing Shapes, basically we are going to Draw line, rectangle, circle, text and ellipse.

 

So now this is the complete code for this lesson.

 

 

So first of all we are going to create an empty image using numpy, because we want to draw our shapes in the empty image.

 

 

For drawing line we can use this code, you can give the position of the line, the thickness and the color of the line.

 

 

If you want to draw rectangle than you can use cv2.rectangle(), and you need to give top left corner and bottom right corner with thickness and color.

 

 

For drawing circle you can use this code, also you need to give the center coordinates, radius, color and thickness.

 

 

This code is used for drawing the ellipse, you need to give center coordinates (x,y location), axes length (major and minor axes lenght), angle = 0, startAngle = 0, endAngle = 180, color and thickness.

 

 

And the last one is drawing text, you can give the x and y position, font size, color and thickness.

 

 

 

Run the complete code and this will be the result.

Python OpenCV Drawing Shapes
Python OpenCV Drawing Shapes

 

 

Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.