基於python的tesseract學習一(初學者)
阿新 • • 發佈:2018-12-03
tesseract是一個OCR庫,可以通過訓練識別出任何字型,也可以識別出任何unicode字元。
一、安裝(本文為win10開發環境)
下載地址:https://digi.bib.uni-mannheim.de/tesseract/
執行安裝檔案,一路下一步就好。
安裝完成需將tesseract的安裝路徑新增到環境變數
檢視版本:
tesseract -v
讀取test.jpg檔案 並把結果寫入text.txt檔案中
tesseract test.jpg text
python中安裝pytesseract
pip install pytesseract
二、python程式碼實現
import pytesseract
from PIL import Image
image = Image.open("pic1.jpg")
text = pytesseract.image_to_string(image)
print(text)
注意:在python中實現需要修改原始碼制定路徑,否側會丟擲沒安裝或者沒新增到環境變數
將tesseract_cmd = 'tesseract'改為安裝路徑,如下:
tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract.exe'