1.函数
import numpy as np
import time
import cv2, math
from PIL import Image, ImageDraw, ImageFont
def cv2ImgAddText(img, text, left, top, textColor=(255, 0, 0), textSize=50):
if (isinstance(img, np.ndarray)): #判断是否OpenCV图片类型
img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
draw = ImageDraw.Draw(img)
fontText = ImageFont.truetype(
"font/simsun.ttc", textSize, encoding="utf-8")
draw.text((left, top), text, textColor, font=fontText)
return cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)
调用frame为图像源:
frame = cv2ImgAddText(frame, "坐标:" + str(X=1,Y=2), 0, 80, (255, 0, 0), 30)
Comments NOTHING