1、下載python4delphi控件包
https://github.com/pyscripter/python4delphi
2、在DelphiIDE裏打開source下面對應pkg,然後compile、install
3、安裝python2.7.16,注意:要安裝相應位長的python程序,一般是安裝32位
4、把python安裝目錄加到系統環境變量path裏,scripts也加到path裏,因爲後續會用到pip腳本安裝一些庫
5、到https://digi.bib.uni-mannheim.de/tesseract/下載tesserocr庫安裝文件
6、將tesseract的語言包添加到環境變量中,在環境變量中新建一個系統變量,變量名稱爲TESSDATA_PREFIX,tessdata是放置語言包的文件夾,一般在你安裝tesseract的目錄下,即tesseract的安裝目錄就是tessdata的父目錄,把TESSDATA_PREFIX的值設置爲它即可
接下來 , 再安裝 tesserocr 即可:
pip install tesserocr pillow
如果通過 pip 安裝失敗,可以嘗試 Anaconda 下的 conda 來安裝:
conda install -c simonflueckiger tesserocr pillow
驗證安裝
測試樣例:
圖片下載:http://images.cnblogs.com/cnblogs_com/Jimc/1316973/o_image.png
(1)用 tesseract 命令測試:
tesseract image.png result -l eng
運行結果如下:
Tesseract Open Source OCR Engine v3.05.01 with Leptonica
(2)利用 Python 代碼測試:
import tesserocr from PIL import Image image = Image.open('image.png') result = tesserocr.image_to_text(image) print(result)
運行結果如下:
PythonWebSpider
另外,還可以直接調用 tesserocr 模塊的 file_to_text() 方法,可以達到同樣的效果:
import tesserocr print(tesserocr.file_to_text('image.png'))
運行結果如下:
PythonWebSpider
如果成功輸出結果,則證明 tesseract 和 tesserocr 都已經安裝成功。