「人生苦短,快用Python」
一、安裝 Tesseract-OCR
在網站 https://digi.bib.uni-mannheim.de/tesseract/ 下載Tesseract-OCR安裝包,如:tesseract-ocr-w64-setup-v5.0.0.20190623.exe,雙擊執行默認安裝。在網站 https://github.com/tesseract-ocr/tessdata 下載tessdata語言包,如:tessdata-master.zip,解壓縮後將所有文件複製到Tesseract-OCR安裝路徑下的tessdata文件夾中。二、安裝 pytesseract
通過pip包管理器安裝tesseract的python綁定庫pytesseract,同時,會自動安裝pytesseract的圖像處理依賴Pillow庫。安裝命令:pip install pytesseract
pip install pillow
測試圖片:
測試代碼:
import pytesseract
from PIL import Image
image = Image.open("1.jpg")
text = pytesseract.image_to_string(image, lang='chi_sim')
print(text)
運行報錯:
pytesseract.pytesseract.TesseractNotFoundError:
tesseract is not installed or it's not in your PATH.
See README file for more information.
解決方法:將pytesseract安裝路徑下的pytesseract.py文件中的行:
tesseract_cmd = 'tesseract' 修改為tesseract可執行文件的真實路徑:如
tesseract_cmd = 'D:/ProgramFiles/Tesseract-OCR/tesseract.exe'
運行結果:
pytesseract.image_to_alto_xml()
pytesseract.image_to_boxes()
pytesseract.image_to_data()
pytesseract.image_to_osd()
pytesseract.image_to_pdf_or_hocr()
pytesseract.image_to_string()
Talk is cheap.
Show me the code.
Long-press QR code to transfer me a reward
Code is God
As required by Apple's new policy, the Reward feature has been disabled on Weixin for iOS. You can still reward an Official Account by transferring money via QR code.