python OpenCV(cv2)putText方法中的中文编码 [英] Chinese encoding in python OpenCV(cv2) putText method

查看:6073
本文介绍了python OpenCV(cv2)putText方法中的中文编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我需要将中文文本放入裁剪后的图像中.我在cv2中使用了"putText"方法来达到目标​​.

For some reason, I need to put Chinese text in an cropped image. I have used the method "putText" in cv2 to achieve the goal.

这是我使用的代码:

cv2.putText(crop_img, u'中文字串'.encode('utf-8'), (200, 200), cv2.FONT_HERSHEY_PLAIN, 3.0, textColor, thickness=4)

但是,图像中显示的所有字符都变为?".我该如何解决这个问题? cv2是否支持中文编码?

However, all the characters shown in the image became "?". How do I solve the problem? Does cv2 support Chinese encoding?

推荐答案

问题是OpenCV仅具有Hershey字体,其中不包括汉字. 因此,您还需要其他东西. 有一个 OpenCV扩展库可以解决该问题.

The problem is that OpenCV only has the Hershey font, which does not include Chinese characters. So you need something else. There is an OpenCV extension library that appears to address the issue.

位于 http://opencv-extension上的程序-library.googlecode.com/svn/doc/r263/classCvxText.html#2b5076328cd67ddd5a4eecc8e00cba3e 当然看起来像是它试图加载字体并在图像中绘制字符.

The program at http://opencv-extension-library.googlecode.com/svn/doc/r263/classCvxText.html#2b5076328cd67ddd5a4eecc8e00cba3e certainly looks like it is trying to load a font and draw characters in an image.

这篇关于python OpenCV(cv2)putText方法中的中文编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆