嘉定企业网站开发,台州网页设计招聘信息,怎么做电商网站 用户画像,排名优化是什么『youcans 的 OpenCV 例程200篇 - 总目录』 【youcans 的 OpenCV 例程200篇】23. 图像添加中文文字
OpenCV 不支持显示中文字符#xff0c;使用 cv2.putText() 时添加的文本字符串不能包含中文字符#xff08;包括中文标点符号#xff09;。在图像中添加中文字符#xff0…『youcans 的 OpenCV 例程200篇 - 总目录』 【youcans 的 OpenCV 例程200篇】23. 图像添加中文文字
OpenCV 不支持显示中文字符使用 cv2.putText() 时添加的文本字符串不能包含中文字符包括中文标点符号。在图像中添加中文字符可以使用 pythonopencvPIL 实现或使用 pythonopencvfreetype 实现。
具体方法详见扩展例程 1.32。
扩展例程1.32 图像中添加中文文字 # 1.32 图像中添加中文文字imgBGR cv2.imread(../images/imgLena.tif) # 读取彩色图像(BGR)from PIL import Image, ImageDraw, ImageFontif (isinstance(imgBGR, np.ndarray)): # 判断是否 OpenCV 图片类型imgPIL Image.fromarray(cv2.cvtColor(imgBGR, cv2.COLOR_BGR2RGB))text OpenCV2021, 中文字体pos (50, 20) # (left, top)字符串左上角坐标color (255, 255, 255) # 字体颜色textSize 40drawPIL ImageDraw.Draw(imgPIL)fontText ImageFont.truetype(font/simsun.ttc, textSize, encodingutf-8)drawPIL.text(pos, text, color, fontfontText)imgPutText cv2.cvtColor(np.asarray(imgPIL), cv2.COLOR_RGB2BGR)cv2.imshow(imgPutText, imgPutText) # 显示叠加图像 imgAddkey cv2.waitKey(0) # 等待按键命令本节完 版权声明 youcansxupt 原创作品转载必须标注原文链接(https://blog.csdn.net/youcans/article/details/125112487) Copyright 2022 youcans, XUPT Crated2021-11-18 【第2章图像的数值运算】 21. 图像的叠加 22. 图像添加非中文文字 23. 图像添加中文文字