一、安裝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