MAC上用python进行图像识别
2019-01-08 本文已影响0人
綦小楓神棍MAX
一、安装pytesseract和PIL
pip命令安装
pip install pytesseract
pip install Pillow
二、安装识别引擎tesseract-ocr
1.安装
//安装tesseract的同时安装训练工具
brew install --with-training-tools tesseract
//安装tesseract的同时安装所有语言,语言包比较大,如果安装的话时间较长,建议不安装,按需选择
brew install --all-languages tesseract
//安装tesseract,并安装训练工具和语言
brew install --all-languages --with-training-tools tesseract
//只安装tesseract,不安装训练工具
brew install tesseract
参考文档:http://khalsa.guru/posts/16
2.下载语言库
下载地址:https://github.com/tesseract-ocr/tessdata
根据自己的需求选择所要的语言库,在这里我们选择的是简体中文所以选择的库是:chi_sim.traineddata
将文件拷贝到到:/usr/local/Cellar/tesseract/4.0.0/share/tessdata目录下
参考文档:https://blog.csdn.net/u010670689/article/details/78374623
三、编写并运行
1.编写py代码
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from PIL import Image
import pytesseract
Image = Image.open('/Users/frj/Desktop/Python/Python_Test/001.jpeg') #打开图片
text = pytesseract.image_to_string(Image,lang='chi_sim') #使用简体中文解析图片
print(text)
image