Tesseract介紹
tesseract是一個挺不錯的OCR引擎,目前的問題是最新的中文資料相對較少,過時、不準確的信息偏多。
tesseract是一個google支持的開源ocr項目,其項目地址:https://github.com/tesseract-ocr/tesseract,目前最新的源碼可以在這里下載。
實際使用tesseract ocr也有兩種方式:1. 動態庫方式 libtesseract 2. 執行程序方式 tesseract.exe
環境
安裝
1.tesseract-orc
安裝的時候需要自行選擇安裝的語言,一些其他國家的語言可以不選擇安裝,我之按安裝了中文,英文和日語。安裝過程和其他軟件一樣。
2.pytesseract
pip install pytesseract
配置環境
1.設置 tesseract-orc路徑
默認情況下tesseract-orc是不被添加到系統的path路徑的,這樣在使用的時候發生FileNotFoundError: [WinError 2] 系統找不到指定的文件錯誤。
解決方法:
設置訓練集的位置
下載的默認訓練集也沒有添加到系統路徑,會報錯
pytesseract.pytesseract.TesseractError: (1, 'Error opening data file //Program Files (x86)//Tesseract-OCR//tessdata/chi_sim.traineddata')
解決方法:
設置環境變量 TESSDATA_PREFIX
C:/Program Files (x86)/Tesseract-OCR/tessdata
實例程序
import pytesseractfrom PIL import Imageimage = Image.open('test.png')code = pytesseract.image_to_string(image)print(code)更多參考:https://pypi.python.org/pypi/pytesseract
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對VEVB武林網的支持。
新聞熱點
疑難解答