Displaying text on Image in Python using OpenCV

putText() Function takes in 7 arguments –

  • Image
  • Text to be displayed
  • Bottom-left corner co-ordinates, from where the text should start
  • Font
  • Font size
  • Color (BGR format)
  • Line width
In [2]:
import cv2
img = cv2.imread('machinelearning.png',1)
cv2.imshow('Machine Learning',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

In [3]:
import cv2
img = cv2.imread('machinelearning.png',1)

output = img.copy() 
text = cv2.putText(output, 'www.machinelearning.org.in', (120, 25),  cv2.FONT_HERSHEY_SIMPLEX, 1, (60, 60, 60), 2)

cv2.imshow('Machine Learning',text)
cv2.waitKey(0)
cv2.destroyAllWindows()