Python OpenCV Example | Write Text on Image

In this python opencv example, we will show you how to write some text on an image. We will use cv2.putText() function to implement it.


This function is defined as:

cv2.putText(image, text, org, font, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]])

Parameters are:

img: Image.
text: Text string to be drawn.
org: Bottom-left corner of the text string in the image.
fontFace: Font type, HersheyFonts.
fontScale: Font scale factor that is multiplied by the font-specific base size.
color: Text color.
thickness: Thickness of the lines used to draw a text.
lineType: Line type

We will use an example to show you how to use this function to draw a text on an image.

For example:

import cv2
img = cv2.imread("bird.jpg")
org = (250, 250)
fontScale = 1
fontFace = 3
color = (255, 255, 255)
thickness = 2
text = "Data Science Learner"
image = cv2.putText(img,text,org,fontFace,fontScale,color)
cv2.imshow("Good Morning",image)

We may see an image as follows:

Python OpenCV Example | Write Text on Image