在Python中使用pytesseract庫(kù)來(lái)識(shí)別圖像中的文本非常簡(jiǎn)單。首先,你需要安裝pytesseract庫(kù)和Tesseract OCR引擎。然后,可以按照以下步驟使用pytesseract來(lái)識(shí)別圖像中的文本:
import pytesseract
from PIL import Image
image = Image.open('image.png')
text = pytesseract.image_to_string(image)
print(text)
上述代碼將輸出識(shí)別出的文本內(nèi)容。你也可以傳遞一些可選參數(shù)給image_to_string()函數(shù),以指定識(shí)別語(yǔ)言、配置文件等。
注意:在使用pytesseract之前,請(qǐng)確保已經(jīng)正確安裝Tesseract OCR引擎,并且已經(jīng)將其路徑添加到環(huán)境變量中。