python工具——Tesseract

OCR可以自动对手写或者印刷字体进行类型转化为机器编码文本字符串,供我们存取和操作

1.安装Tesseract

(1)Ubuntu16下

sudo apt-get install tesseract-ocr

验证Tesseract是否安装成功

tesseract -v

(2)windows下

下载https://digi.bib.uni-mannheim.de/tesseract/

添加到环境变量的path中

验证Tesseract是否安装成功

tesseract -v

2.用命令行进行测试

tesseract 123.png result

 

 说明:

  第一个参数为图片名称

  第二个参数result 为结果保存的目标文件名称

result.txt的内容

tessdata的格式:

tesseract 图片名称 生成的结果文件的名称 字库

 3.使用Python

安装pytesseract

pip install pytesseract

提取图片中的文字

from PIL import Image
import pytesseract

image = Image.open('123.png')
content = pytesseract.image_to_string(image)   # 解析图片
print(content)

4.识别汉字

下载字库

https://github.com/tesseract-ocr/tessdata

下载后放到Tesseract-OCR项目的tessdata文件夹里面

tesseract hello.png result -l chi_sim

python实现

在pytesseract 库的 image_to_string() 方法里加个参数lang='chi_sim',这个就是引用对应的中文语言包

中文语言包的全名是 chi_sim.traineddata

from PIL import Image
import pytesseract

image = Image.open('hello.png')
content = pytesseract.image_to_string(image,lang='chi_sim')   # 解析图片
print(content)

如果识别的效果不理想,可以使用 jTessBoxEditor 提高文字识别准确率

下载https://sourceforge.net/projects/vietocr/files/jTessBoxEditor/

 

posted @   慕尘  阅读(1219)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示