![]() |
VOOZH | about |
cv2.putText() is an OpenCV function used to write text directly on an image. It lets you choose the text content, position, color, thickness, and font style. This is commonly used for labeling objects, adding captions, or marking coordinates on images during computer vision tasks.
Note: For this article we will use a sample image "logo.png", to download click here.
Example: This example loads an image and writes a single text string on it using default settings.
Output
Explanation: cv2.putText() writes "Hello" at position (40, 40) using a simple font, size 1, blue color (255, 0, 0) and thickness 2.
cv2.putText(image, text, org, font, fontScale, color, thickness=1, lineType=cv2.LINE_8, bottomLeftOrigin=False)
Parameters:
Example 1: This example adds a simple text label in the top-left corner of an image.
Output
Explanation: "OpenCV" is placed at (30, 40) and drawn in green (0, 255, 0) using a smooth font size 1.
Example 2: This example positions text near the bottom of the image using a different color and thicker font.
Output
Explanation: "Sample Text" uses a thicker red color (0, 0, 255) and font scale 1.2.
Example 3: Here the text is drawn with the image origin interpreted from the bottom-left by enabling bottomLeftOrigin=True.
Output
Explanation: bottomLeftOrigin=True makes OpenCV treat the bottom-left of the image as the origin, reversing how the Y-coordinate grows.