In the previous section, we created various shapes on images. Now, we will learn how to write text on images. Writing text on an image is similar to drawing shapes. Let's see an example of writing on an image:
# Let's create a black image
img_shape=(600,800,3)
black_image = np.zeros(shape=image_shape,dtype=np.int16)
# Write on black image
text = cv2.putText(black_image,'Thanksgiving',(10,500),
cv2.FONT_HERSHEY_SIMPLEX, 3,(255,0,0),2,cv2.LINE_AA)
# Display the image
plt.imshow(text)
This results in the following output:
In the preceding example, we created a blank image with the color black. We have written text on an image using the putText() function. The putText() function will take the following arguments: image, text, coordinates of the bottom-left corner, font, fontScale, color, thickness, and linetype.