Sunday 15 July 2018

Write a text on image using openCV-Python

Adding Text to Images:

To put texts in images, you need specify following things.
  • Text data that you want to write
  • Position coordinates of where you want put it (i.e. bottom-left corner where data starts).
  • Font type (Check cv2.putText() docs for supported fonts)
  • Font Scale (specifies the size of font)
  • regular things like color, thickness, lineType etc. For better look, lineType = cv2.LINE_AA is recommended.
We will write OpenCV on our image in white color.
import numpy as np
import cv2
font = cv2.FONT_HERSHEY_SIMPLEX
# Create a black image
img = np.zeros((512,512,3), np.uint8)

cv2.putText(img,'Hack Projects',(10,500), font, 1,(255,255,255),2)
#Display the image
cv2.imshow("img",img)

cv2.waitKey(0)
Running the program you will see the blue line.

text

No comments:

Post a Comment