人脸识别时,执行以下代码使用cv2.putText()函数标注人脸名称但是中文总是显示出来的??,试了很多方法还是失败了,询问ai它说使用ecode函数将name转换为‘utf-*#xff0c;但是报错说puttext需要输入一个字符串所以我把puttext函数中的name改为str(name),代码如下中文可以正常显示。
中文显示乱码的源代码:
for (top, right, bottom, left), name in zip(face_locations, face_names): if not name: continue # 绘制面部区域框 cv2.rectangle(frame,(left,top),(right,bottom), (0, 0, 255), 2) # 在面部区域下绘制人名 cv2.rectangle(frame, (left, bottom - 25), (right, bottom), (0, 0, 255), cv2.FILLED) font = cv2.FONT_HERSHEY_DUPLEX cv2.putText(frame,name, (left + 6, bottom - 6), font, 1, (255, 255, 255), 1)。
中文正常显示的代码:
for (top, right, bottom, left), name in zip(face_locations, face_names): if not name: continue # 绘制面部区域框 cv2.rectangle(frame,(left,top),(right,bottom), (0, 0, 255), 2) # 在面部区域下绘制人名 cv2.rectangle(frame, (left, bottom - 25), (right, bottom), (0, 0, 255), cv2.FILLED) font = cv2.FONT_HERSHEY_DUPLEX cv2.putText(frame,str(name), (left + 6, bottom - 6), font, 1, (255, 255, 255), 1)。
注:face_names是中文列表,例如:face_names=['人名1', '人名2', '人名3']。
注:face_names是中文列表,例如:face_names=['人名1', '人名2', '人名3']。
但name本身的类型是str,str(name)之后还是str:。
虽然解决了中文显示乱码的问题,但是我没有找到的原理c;希望懂的人能回答,感恩!!!也希望对大家有所帮助。 顶: 11踩: 61928
cv2解决opencv.puttext函数不能显示中文问题
人参与 | 时间:2025-06-24 13:16:37
相关文章
- 中国最大的南极磷虾捕捞船从连江起航
- B端:MES系统非常困难,一篇文章告诉你如何设计
- 【MySQL】详解数据库约束、聚合查询和联合查询
- websocket连接显示了Python执行websocket连接 has no attribute enabletrace错误
- 佳能r10微单RF
- Python中的queue模块使用[学习经验]
- 一文通透想颠覆Transformer的Mamba:从SSM、HiPPO、S4到Mamba(被誉为Mamba最佳解读)
- 【Linux】解锁进程地址空间奥秘,高效环境变量的实战技巧
- 零跑 B10 预售:激光雷达智能驾驶进入 15 万内,10.98 万
- 一个可一键生成短视频的AI大模型,亲测可用
评论专区