python實現圖像文字識別,我們需要安裝 pytesseract 和 pillow 這兩個庫,直接用 pip 安裝就好。
其次還需要安裝 Tesseract-OCR.exe 這個軟件。
下面是實現代碼:
import pytesseract from PIL import Image pytesseract.pytesseract.tesseract_cmd = 'D://Python//Tesseract-OCR//tesseract.exe'//Tesseract-OCR安裝路徑 image = Image.open('D://3.png')//圖片路徑 text = pytesseract.image_to_string(image,lang='chi_sim')//chi_sim為中文包
print(text)
英文圖片演示:
演示結果:
中文圖片演示:
演示結果: