PaddleOCR icon indicating copy to clipboard operation
PaddleOCR copied to clipboard

cpp_infer调用PP-OCRv5模型会识别中文乱码

Open futureflsl opened this issue 5 months ago • 4 comments

🔎 Search before asking

  • [x] I have searched the PaddleOCR Docs and found no similar bug report.
  • [x] I have searched the PaddleOCR Issues and found no similar bug report.
  • [x] I have searched the PaddleOCR Discussions and found no similar bug report.

🐛 Bug (问题描述)

cpp_infer调用PP-OCRv5模型会识别中文乱码,我看目前已经支持deploy/cpp-infer已经支持PP-OCRv5模型,然后编译调用发现中文总是乱码,尝试将v5对应字典文件ppocr_keys.txt分别改成utf8或者ansi编码都不行。目前猜测代码里面有bug

🏃‍♂️ Environment (运行环境)

截止2025年6月17日最新main分支代码

🌰 Minimal Reproducible Example (最小可复现问题的Demo)

英文和数字都是正常的,中文全是乱码 原图:

Image

识别结果:

Image

futureflsl avatar Jun 17 '25 01:06 futureflsl

目前已确认是bug,我已经发现问题。ocr_rec.h头文件第77行开始,他会自动强制写出inference.yml类别,之后保存为uft8格式导致识别乱码,当你指定keys.txt路径它不会读取指定字典文件,而是还是强制写出字典为utf8编码即使你手动改成ansi也不行。正确做法是注释掉强制写出部分。

Image 最后就可以了:

Image 综上所述,windows上字典文件必须是ansi编码才行,uft8中文会乱码。

futureflsl avatar Jun 17 '25 02:06 futureflsl

感谢您的反馈,我们评估下是否需要对Windows进行相关兼容性调整

changdazhou avatar Jun 18 '25 03:06 changdazhou

这看起来只是控制台乱码?

GeTOUO avatar Jun 19 '25 01:06 GeTOUO

控制台先执行 chcp 65001 再执行ocr程序试试

DHclly avatar Jun 19 '25 06:06 DHclly

注释掉之后直接就变成了这种,字典的路径用绝对路径或者相对路径都会报错这个,你有遇到过嘛

Image

shanshuiyao avatar Jun 21 '25 08:06 shanshuiyao

windows上字典文件必须是ansi编码才行,uft8中文会乱码 这个很可能是windows控制台编码不是utf-8哈,可以调整一下编码。

zhang-prog avatar Jul 24 '25 06:07 zhang-prog

PaddleOCR 3.2 版本已发布,支持 OCR 产线 C++ 本地部署方案,功能及精度效果与 Python 方案保持一致。欢迎体验:

通用 OCR 产线 C++ 部署 - Linux 通用 OCR 产线 C++ 部署 - Windows

如果在使用过程中有任何问题,欢迎提 issue,我们会及时跟进并解决! @futureflsl

zhang-prog avatar Aug 22 '25 07:08 zhang-prog

The issue has no response for a long time and will be closed. You can reopen or new another issue if are still confused.


From Bot

TingquanGao avatar Sep 22 '25 12:09 TingquanGao