主要參考官方的編譯,梳理一下整個流程css
The build instructions for Linux also apply to other UNIX like operating systems.html
If they are not already installed, you need the following libraries (Ubuntu 16.04/14.04):linux
1、安裝依賴:
git
sudo apt-get install g++ autoconf automake libtool autoconf-archive pkg-config libpng12-dev libjpeg8-dev libtiff5-dev zlib1g-devlibleptonica-dev
-y
或者一條一條複製:libleptonica-dev
sudo apt-get install g++ # or clang++ (presumably) sudo apt-get install autoconf automake libtool sudo apt-get install autoconf-archive sudo apt-get install pkg-config sudo apt-get install libpng12-dev sudo apt-get install libjpeg8-dev sudo apt-get install libtiff5-dev sudo apt-get install zlib1g-dev
if you plan to install the training tools, you also need the following libraries:github
安裝訓練所依賴的庫:
sudo apt-get install libicu-dev libpango1.0-dev libcairo2-dev
或者:
sudo apt-get install libicu-dev sudo apt-get install libpango1.0-dev sudo apt-get install libcairo2-dev
You also need to install Leptonica. Ensure that the development headers for Leptonica are installed before compiling Tesseract.ubuntu
Tesseract versions and the minimum version of Leptonica required:windows
2、安裝leptonica,app
由於tesseract依賴這個庫,不然在configure的時候會提示ide
最新的tesseract 4.0 及3.05 須要從Leptonica 源代碼編譯字體
git clone https://github.com/DanBloomberg/leptonica.git
cd leptonica
./configure
make -j8 && make install
Tesseract | Leptonica | Ubuntu |
---|---|---|
4.00 | 1.74.2 | Must build from source |
3.05 | 1.74.0 | Must build from source |
3.04 | 1.71 | Ubuntu 16.04 |
3.03 | 1.70 | Ubuntu 14.04 |
3.02 | 1.69 | Ubuntu 12.04 |
3.01 | 1.67 |
One option is to install the distro's Leptonica package:
sudo apt-get install libleptonica-dev
but if you are using an oldish version of Linux, the Leptonica version may be too old, so you will need to build from source.
The sources are at https://github.com/DanBloomberg/leptonica . The instructions for building are given in Leptonica README.
Note that if building Leptonica from source, you may need to ensure that /usr/local/lib is in your library path. This is a standard Linux bug, and the information at Stackoverflow is very helpful.
Please follow instructions in https://github.com/tesseract-ocr/tesseract/wiki/Compiling--GitInstallation
Also read Install Instructions
3、編譯tesseract
clone源代碼 :
clone源代碼 :
git clone https://github.com/tesseract-ocr/tesseract.git tesseract-ocr
cd tesseract-ocr ./autogen.shautoreconf -i
./configure
這時會提示:
Configuration is done.
You can now build and install tesseract by running:
$ make
$ sudo make install
Training tools can be built and installed with:
$ make training
$ sudo make training-install
繼續編譯,先編譯tesseract,在編譯安裝 training
autoreconf -i
make sudo make install
make training
make training-install
sudo ldconfig
到這就完成了真個編譯過程,這個時候 在命令行中 輸入tesseract 會提示怎麼用。
4、配置字體庫
是一個配置目錄能夠以此爲基礎把全部用的語言包放在這裏面tesseract/tessdata
cdtesseract
的父目錄
cp -r tesseract/tessdata/ tessdata/
下載須要的語言包 https://github.com/tesseract-ocr/tessdata_best 裏面有各類語言包,這是訓練好的語言包。簡體中文下載:chi_sim.traineddata chi_sim_vert.traineddata
tesseract
下載好的語言包 放在tessdata目錄裏面
設置環境變量 tessdata
的父目錄。如:export TESSDATA_PREFIX=/media/sf_E_DRIVE/src-test/tesseract_all/tesseract_linux
5、使用tesseract
5、使用tesseract
具體用法可參考tesseract的使用說明
tesseract /home/app/1.png output -l chi_sim
識別這張圖片。輸出到output.txt 裏面,用chi_sim 識別(不用加
/home/app/1.png
.traineddata,會默認加
)
cat output.txt 能夠查看剛纔的內容
具體用法可參考tesseract的使用說明
tesseract /home/app/1.png output -l chi_sim
識別這張圖片。輸出到output.txt 裏面,用chi_sim 識別(不用加
/home/app/1.png
.traineddata,會默認加
)
cat output.txt 能夠查看剛纔的內容/home/app/1.png
/home/app/1.png.traineddata,會默認加
Tesseract can be configured to install anywhere, which makes it possible to install it without root access.
To install it in $HOME/local:
./autogen.sh ./configure --prefix=$HOME/local/ make install
To install it in $HOME/local using Leptonica libraries also installed in $HOME/local:
./autogen.sh LIBLEPT_HEADERSDIR=$HOME/local/include ./configure \ --prefix=$HOME/local/ --with-extra-libraries=$HOME/local/lib make install
tessdata
directory (e.g. 'mv tessdata $TESSDATA_PREFIX' if defined TESSDATA_PREFIX
)You can also use:
export TESSDATA_PREFIX=/some/path/to/tessdata
to point to your tessdata directory (example: if your tessdata path is '/usr/local/share/tessdata' you have to use 'export TESSDATA_PREFIX='/usr/local/share/').