一、安装Tesseract
以window安装为例,参考:https://segmentfault.com/a/1190000014086067
note:
使用虚拟环境需要:
在 python 环境(或虚拟环境) \Lib\site-packages\pytesseract
目录下找到 pytesseract.py
,
打开 pytesseract.py
, 在 32行 ,找到 变量 tesseract_cmd,修改 tesseract_cmd 值:
tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
参考:https://www.pythonheidong.com/blog/article/753756/41839878d41e6db7e422/
二、python code
a.安装依赖
pip install pytesseract pip install pillow
b.sample code
simple.pnd为测试图片,注意是否当前的路径。
import pytesseract
from PIL import Imageimage = Image.open("simple.png")
code = pytesseract.image_to_string(image)
print(code)
参考:https://segmentfault.com/a/1190000014091417