frame = puttext_cn(frame, names[results[idx] + 1], (bbox[0], bbox[1]), color=(255, 0, 0), size=26) def puttext_cn(img,text,pt,color=(255,0,0),size=16): if (isinstance(img, np.ndarray)): # 判断是否OpenCV图片类型 img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) draw = ImageDraw.Draw(img) # 字体的格式 fontStyle = ImageFont.truetype( "simhei.ttf", size, encoding="utf-8") # 绘制文本 draw.text(pt, text, color, font=fontStyle) # 转换回OpenCV格式 return cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)