Python Draw Text on Image

Use PIL

1
2
3
4
5
6
7
8
import PIL.ImageDraw
import PIL.Image
import PIL.ImageFont

pil_img = PIL.Image.fromarray(bb_img)
draw = PIL.ImageDraw.Draw(pil_img)
font = PIL.ImageFont.truetype("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf",20)
draw.text((10, 10),"Frame: %09d"%(iframe),(255,0,0),font=font)

Use OpenCV

1
2
import cv2
cv2.putText(cv_img, 'Frame: %d'%(iframe), (10,20), cv2.FONT_HERSHEY_SIMPLEX, 0.65, (0,0,255), 3)