1.在anaconda prompt中安裝pytesseract和pillow: pip install pytesseract
2.安裝tesseract-ocr的識别引擎 https://github.com/UB-Mannheim/tesseract/wiki
進行配置:需要在兩個地方修改,參考https://www.cnblogs.com/chenshengkai/p/11318272.html
檢視是否安裝成功:tesseract --version
修改pytesseract.py檔案,‘tesseract’修改為安裝tesseract-ocrde的安裝目錄
3.在pycharm中編寫代碼
圖檔:
代碼:
from PIL import Image
import pytesseract
image = Image.open('img/0.png')
content = pytesseract.image_to_string(image) # 解析圖檔
print(content)
print("hello")
運作截圖:
4.使用其他語言包
先下載下傳語言包,可參考:https://blog.csdn.net/qq_38161040/article/details/90727456
下載下傳完,直接放到安裝位置的tessdata檔案夾裡就好了
使用時要在pytesseract 庫的 image_to_string() 方法裡加個參數