Tesseract开源的OCR工具及python pytesseract安装使用

发布时间 2023-07-25 13:27:11作者: HIIT

一 、介绍

Tesseract是一款由Google赞助的开源OCR。 pytesseract是python包装器,它为可执行文件提供了pythonic API。

Tesseract 已经有 30 年历史,开始它是惠普实验室的一款专利软件,在2005年后由Google接手并进一步开发和完善。Tesseract支持多种语言文字的检测和识别,包括中文、英语、德语、法语、意大利语等多种主要语言,同时也支持针对特定场景或应用的领域OCR开发。

Tesseract基于机器学习技术,使用了多层神经网络以及支持向量机(SVM)等算法进行文字特征提取和识别。同时,Tesseract通过图像预处理、二值化、斑点去除和边框检测等多个环节优化页面处理流程,并且提供了多种字体、大小、旋转角度和噪声等挑战场景下的训练数据集,使得识别精度可以获得不错的性能表现。

 

二、安装

1、python安装pytesseract

pip install pytesseract -i https://pypi.tuna.tsinghua.edu.cn/simple/

 2、python安装Pillow图片处理

pip install Pillow -i https://pypi.tuna.tsinghua.edu.cn/simple/

 

3、pytesseract需要和安装在本地的tesseract-ocr.exe文件一起使用

tesseract-ocr.exe 下载地址 github

默认安装勾选中文语言包

 4、系统变量path添加tesseract的安装路径xx:\Program Files\tesseract

系统变量path详细添加,或者遇到没有找到文件问题请看我的下一篇

三、使用

import pytesseract
from PIL import Image
#英文lang='eng'#中文:lang='chi_sim'#中英文混合:lang='chi_sim+eng'
text = pytesseract.image_to_string(Image.open(r"./img/a.jpg"), lang='eng')
print("英文:",text)