pytesseract相关

1.tesseract-ocr是什么:

tesseract-ocr,简称tesseract,windows下载地址https://github.com/UB-Mannheim/tesseract/wiki

是google开发的一款基于ocr识别的开源工具

可以单独运行:

tesseract imagename outputbase [-l lang] [--oem ocrenginemode] [--psm pagesegmode] [configfiles...]

也可以作为其他语言的类库被调用(即本文重点pytesseract)

tesseract由C++语言编写,目前最新的的内部实现增添了lstm神经网络

默认安装语言是英文,如果有额外的语言需求可从https://github.com/tesseract-ocr/tessdata下载指定语言包(例如chi_tra.traineddata

然后把对应语言包放到tesseract安装目录例如D:/tesseract-OCR/的子文件夹tessdata中即可获得对应的语言支持(如本例为繁体中文)

2.pytesseract:

pytesseract是python的第三方脚本库,内部实现实际上是tesseract

安装方法为pip/conda install pytesseract

使用方法:import pytesseract

注意:首先确保tesseract在环境变量中:

pytesseract.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'
例如我的tesseract安装目录在D:/tesseract-OCR/
就要事先运行
tesseract_cmd = r'D:/tesseract-OCR/'

pytesseract主要方法如下:

1)image_to_string(Image):将图像识别为字符串

2)get_languages(Image):列出可用语言

3)image_to_boxes(Image):获得边界框的估计值

4)image_to_data(Image):获取详细数据,包括框,置信度,行号和页码

5)image_to_osd(Image):获取有关方向和脚本检测的信息

6)image_to_pdf_or_hocr(Image):将图片转换成pdf / hocr(通过指定extension)

更多详细用法可参阅https://pypi.org/project/pytesseract/

3.pytesseract源码分析

4.如何通过图像预处理优化pytesseract

https://tesseract-ocr.github.io/tessdoc/ImproveQuality

https://stackoverflow.com/questions/9480013/image-processing-to-improve-tesseract-ocr-accuracy

原文地址:https://www.cnblogs.com/J14nWe1/p/14372683.html