赞
踩
from PIL import Image, ImageDraw, ImageFont
import cv2
def cv2_img_add_text(img, text_str, left, top, text_color, text_size):
if isinstance(img, np.ndarray):
img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
draw = ImageDraw.Draw(img)
fontText = ImageFont.truetype("msjh.ttc", text_size, encoding="utf-8")
draw.text((left, top), text_str, text_color, font=fontText)
return cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)
# frame为opencv读取的数据图像,BGR通道格式
position_x=20
position_y=20
frame = cv2_img_add_text(frame, str(COUNTER_EYE),position_x, position_y, (55, 255, 155), 20)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。