Python之图片OCR识别(Mac)
2018-05-17 本文已影响758人
CrazySteven
因为经常给朋友发的信息来源是一张图片,就想到了用Python处理下,就省的敲字了。。。
安装tesseract
brew install tesseract
安装pytesseract
pip3 install pytesseract
下载相应的语言包(以中文为例)
打开下载链接,下载需要的语言包,如中文需下载chi_sim.traineddata
,将下载好的语言包放到/usr/local/Cellar/tesseract/3.05.01/share/tessdata/
路径下。
OCR识别(中文)
import pytesseract
from PIL import Image
# open的是图片的路径
image = Image.open('/Users/apple/Desktop/640.jpg')
code = pytesseract.image_to_string(image, lang='chi_sim')
print(code)
识别时间有点长,但准确率还不错,耐心点即可。