Python-图片添加中文

Python 图片添加中文文字。

1
2
3
4
5
6
7
8
9
10
11
12
img_PIL = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
font = ImageFont.truetype(fontLib, 40)
fillColor = (255, 0, 255)
position = (int((videoWidth - 65) * widthScale), 40)
str = "实时人数:%d" %(lastPeopleCount)
if not isinstance(str, unicode):
str = str.decode('utf8')

draw = ImageDraw.Draw(img_PIL)
draw.text(position, str, font = font, fill = fillColor)
imgNew = cv2.cvtColor(np.asarray(img_PIL), cv2.COLOR_RGB2BGR)
img[:] = imgNew[:]