python opencv输出中文的方法 putText 支持中文输出 您所在的位置:网站首页 paint的汉语 python opencv输出中文的方法 putText 支持中文输出

python opencv输出中文的方法 putText 支持中文输出

2023-12-22 03:45| 来源: 网络整理| 查看: 265

python opencv输出中文

opencv在视频中通过putText函数能添加文字,但对于中文则无能为力。一般需要FreeType字体库进行处理,在python可以通过PIL转换一下。  现将在视频中添加中文封装成函数如下:

def paint_chinese_opencv(im,chinese,pos,color): img_PIL = Image.fromarray(cv2.cvtColor(im,cv2.COLOR_BGR2RGB)) font = ImageFont.truetype('NotoSansCJK-Bold.ttc',25) fillColor = color #(255,0,0) position = pos #(100,100) if not isinstance(chinese,unicode): chinese = chinese.decode('utf-8') draw = ImageDraw.Draw(img_PIL) draw.text(position,chinese,font=font,fill=fillColor) img = cv2.cvtColor(np.asarray(img_PIL),cv2.COLOR_RGB2BGR) return img 使用方法: paint_chinese_opencv(image,str,point,color) //Mat 图片,string "中文",Point (30,30),color (0,0,255)

ubuntu字体通常保存在:/usr/share/fonts/opentype/noto/  可通过locate *.ttc查找



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有