python在图片上写汉字


1、python opencv的putText只能画英文上去

2、借鉴这个https://blog.csdn.net/dcrmg/article/details/79108491 使用pil

首先,你需要下载一个tff包,http://www.downcc.com/font/248408.html这个是在网上搜索的微软雅黑的文字包,随便你放在哪里,只有能读到就好了。接下来就按照下面的代码:

img_PIL = Image.fromarray(cv2.cvtColor(image_show, cv2.COLOR_BGR2RGB))
font = ImageFont.truetype('/unsullied/sharefs/zhouxingyu/isilon-home/CarPlate/test_scripts/chepai/msyh.ttf', 30)
fillColor = (255,0,0)
position = (30,300)
draw = ImageDraw.Draw(img_PIL)
draw.text(position, plate_num, font=font, fill=fillColor)

img_OpenCV = cv2.cvtColor(np.asarray(img_PIL),cv2.COLOR_RGB2BGR)

cv2.imshow('plate img',img_OpenCV)

注意pil和opencv的互相转换


 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM