在Mac OS 下 build Tesseract4.0 源碼並在命令行中使用


作者電腦:Mac Mini 系統信息:OS X EI Capitan 10.11.6

Tesseract4.0github地址:https://github.com/tesseract-ocr/tesseract/wiki/4.0-with-LSTM

build 步驟:

參考Tesseract github上的官方文檔:https://github.com/tesseract-ocr/tesseract/wiki/Compiling#macos

  1. 安裝homebrew

直接在終端中輸入:ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安裝過程中需要鍵入一次回車

       2. 使用brew命令安裝依賴

brew install automake autoconf
brew install autoconf-archive
brew install pkgconfig
brew install icu4c
brew install leptonica
brew install gcc
   3. compile 
git clone https://github.com/tesseract-ocr/tesseract/
在這一步可能會有錯誤提示:

fatal: could not create work tree dir 'tesseract': Permission denied

此時需要我們使用sudo命令創建一個具有寫權限的文件夾,然后把tesseract的源碼clone至此文件中

 

也可能有錯誤提示:

Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.

我們需要:

1、打開終端,輸入  sudo xcodebuild -license

 

2、終端提示敲回車鍵(enter)打開許可協議,照做

 

3、終端提示 按下  “space” 鍵閱讀許可協議,按“q” 不閱讀

 

4、最終,終端會出現三個選項,agree 、print、cancel,不用想,能不是agree 嗎!輸入agree,然后enter

 

     4. 接下來:

cd tesseract
./autogen.sh
這一步可能會有錯誤:“

Failed to find libtoolize or glibtoolize...“

只需安裝libtool即可: brew install libtool
./configure CC=gcc-6 CXX=g++-6 CPPFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib
make -j
sudo make install  # if desired
make training
5.試一下好不好使
首先要下載相關語言的數據文件,英語數據文件下載地址:eng.traineddata 其他數據文件下載地址:https://github.com/tesseract-ocr/tesseract/wiki/Data-Files#data-files-for-version-400

數據文件下載完成后,需要把它move到:/tesseract/tessdata 路徑下
然后如果出現錯誤:

Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory.

就使用命令:

export TESSDATA_PREFIX=/Users/naver/code/tesseract/

接下來要提前創建一個文件來存儲識別的文字結果,如:out

然后輸入測試命令:

tesseract /Users/naver/Downloads/test.jpg out

test.jpg 為要識別的圖片,然后識別結果會存儲在out文件中。

詳細參數介紹參見官方github文檔:https://github.com/tesseract-ocr/tesseract/wiki/Command-Line-Usage

https://github.com/tesseract-ocr/tesseract/blob/master/doc/tesseract.1.asc#config-files-and-augmenting-with-user-data

其他參考鏈接:

http://blog.csdn.net/xiaochunyong/article/details/7193744

http://www.zmonster.me/2015/04/17/tesseract-install-usage.html

http://git.malu.me/tesseract%E4%BD%BF%E7%94%A8%E8%AE%B0%E5%BD%95/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM