pip3 install pillow
pip3 install pytesseract
brew install tesseract
brew install tesseract-lang //下載語言套件for Mac
for Windows
pip install pillow
pip install pytesseractfor Windows
for Windows
Let's coding!
from PIL import Image //使用影像處理套件
import pytesseract //引入pytesseract先匯入pytesseract模組
img = Image.open("這裡放要辨識的圖片.jpg“)打開圖片
tesseract_cmd = r"這裡放剛剛安裝的tesseract的絕對路徑"for Mac
for Windows
pytesseract.pytesseract.tesseract_cmd = "這裡放剛剛安裝的tesseract.exe的絕對路徑"text = pytesseract.image_to_string(img,lang="這裡放要辨識的語言")
//語言格式:eng,chi_tra(繁),chi_sim(簡)
print(text)若有多種語言則使用“+”號連結
from PIL import Image
import pytesseract
img = Image.open("test01.jpg")
tesseract_cmd = r"/usr/local/Cellar/tesseract/4.1.1/bin/tesseract"
text = pytesseract.image_to_string(img,lang="chi_tra+eng")
print(text)for Mac
for Windows
from PIL import Image
import pytesseract
img = Image.open("test01.jpg")
pytesseract.pytesseract.tesseract_cmd = r"C:\Users\Sam\AppData\Local\Tesseract-OCR\tesseract.exe"
text = pytesseract.image_to_string(img,lang="chi_tra+eng")
print(text)