针对mac系统
tesseract项目主页:https://github.com/tesseract-ocr/tesseract
pyocr项目主页:https://github.com/jflesch/pyocr
1. tesseract安装
终端输入以下命令(未安装brew
可前往这里安装)
|
|
2. tesseract语言包
- 各语言包下载地址:https://github.com/tesseract-ocr/tesseract/wiki/Data-Files
- 语言包安放路径:/usr/local/Cellar/tesseract/3.05.00/share/tessdata(3.05.00为版本号) 或:/usr/local/share/tessdata
3. tesseract手册
通过man或者--help(-h)命令查看帮助手册
|
|
4. PyOCR
4.1 常用API
4.1.1 pyocr.get_available_tools()
列出可用的ocr程序(返回list),Pyocr目前支持Tesseract和Cuneiform,这里我们只讨论Tesseract。
|
|
4.1.2 pyocr.tesseract.is_available()
tesseract是否可用。这里没有安装libtesseract,所以返回false
。
|
|
4.1.3 pyocr.tesseract.get_name()
获取tesseract的名称
|
|
4.1.4 pyocr.tesseract.get_version()
版本号
|
|
4.1.5 pyocr.tesseract.get_available_builders()
可用的builder,返回的是list。
|
|
4.1.6 pyocr.tesseract.get_available_languages()
可用的语言,返回的是list。博主安装时默认安装的语言包只有eng
和osd
,其他语言包可自行添加。
|
|
4.1.7 pyocr.tesseract.cleanup()
删除某个文件(忽略不存在的文件,参数为文件名)
4.1.8 pyocr.tesseract.can_detect_orientation
是否可以检测方向
|
|
4.1.9 pyocr.tesseract.detect_orientation
检测图片方向,Tesseract 只能返回0, 90, 180, 270这四个角度。
|
|
4.1.10 pyocr.tesseract.image_to_string
图像内容转字符串
5. 用法
下面沿着官方文档走一遍(以img1和img2为例):
img1:
img2:
5.1 Initialization初始化
|
|
5.2 Image to text
参数:
image — 先通过PIL模块打开DISK中的图片.
lang — 指定语言.
builder — 默认的builder是TextBuilder.
返回:
返回的类型随所指定的builder而不同。
|
|