Drawing Shapes and Text on Images
OpenCV provides the following drawing functions to draw geometric shapes on images. It also provides functions to write text on images.
Syntax |
Purpose |
---|---|
line(image, start_coordinates, end_coordinates, color_in_bgr, line_thickness) | By using this function we can create a line in the image from start coordinates to end coordinates with a certain thickness which can be mentioned specifically as well. |
rectangle(image,top_left_vertex_coordinates, lower_right_vertex_coordinates, color_in_bgr, thickness) |
This function is used to create a box with a certain thickness and color which can be specified as well. |
circle(image, center_coordinates, radius, color, thickness) | It is used to draw a circle whose centre and radius length is given with a certain thickness and the colour of the strokes of the circle. |
polylines(image, [pts], isClosed, color, thickness) | It is used to draw a polygon on any image whose vertex coordinates are provided. |
putText(image, ‘TextContent’, ‘text_starting_point_coordinates’, ‘fontToBeUsed’, ‘font_size’, ‘text_color’, ‘text_thickness’, ‘line_type’) |
It is used to write some text on the image loaded. |
Draw Line
The cv2.line() method is used to draw the line on an image.
cv2.line(image, (start_coordinates), (end_coordinates), (color_in_bgr),
line_thickness)
Draw Rectangle
The cv2.rectangle() method is used to draw a rectangle on an image.
cv2.rectangle(image, (‘top_left_vertex_coordinates’),
(‘lower_right_vertex_coordinates’),
(‘stroke_color_in_bgr’), ‘stroke_thickness’)
Draw Circle
The cv2.circle() method is used to draw a circle on an image.
cv2.circle(image, (‘center_coordinates’), (‘circle_radius’),
(‘color_in_bgr’), ‘stroke_thickness’)
Draw Polygon
The cv2.polylines() method is used to draw a polygon on any image.
cv2.polylines(image, [pts], isClosed, color, thickness)
Writing Text
The cv2.putText() method is used to write some text on an image.
cv2.putText(image, ‘TextContent’, (‘text_starting_point_coordinates’),
‘fontToBeUsed’, ‘font_size’, (‘text_color’, ‘text_thickness’, ‘line_type’)
Python OpenCV Cheat Sheet
The Python OpenCV Cheat Sheet is your complete guide to mastering computer vision and image processing using Python. It’s designed to be your trusty companion, helping you quickly understand the important ideas, functions, and techniques in the OpenCV library. Whether you’re an experienced developer needing a quick reminder or a newcomer excited to start, this cheat sheet has got you covered.
In this article, we’ve gathered all the vital OpenCV concepts and explained them in simple terms. We’ve also provided practical examples to make things even clearer. You’ll learn everything from how to handle images to using advanced filters, spotting objects, and even exploring facial recognition. It’s all here to help you on your journey of discovering the amazing world of computer vision.
Table of Content
- Python OpenCV Cheat Sheet 2023
- Core Operations
- Drawing Shapes and Text on Images
- Arithmetic Operations on Images
- Morphological Operations on Images
- Geometric Transformations on Image
- Image Thresholding
- Edge/Line Detection (Features)
- Image Pyramids
- Changing the Colorspace of Images
- Smoothing Images
- Working With Videos
- Camera Calibration and 3D Reconstruction