由于在服务器上安装tesseract yum只能拉到3.X版本 而测试来看4.0以上版本识别效果比3.x要好很多。于是只能通过编译代码形式安装最新版了
首先在机器上找个目录 打开官方git https://github.com/tesseract-ocr
打到4.1分支 我们在服务器上找个目录 git clone https://github.com/tesseract-ocr/tesseract.git
- 如果新机器就随手安装上工具包
yum install gtk2-devel yasm glibc.i686 libstdc++.so.6 libgtk-x11-2.0.so libatk-1.0.so.0 libcairo.so.2 libcups.so.2 libgdk-x11-2.0.so.0 libgdk_pixbuf-2.0.so.0 libgtk-x11-2.0.so.0 libpango-1.0.so.0 libpangocairo-1.0.so.0 libICE.so.6 libSM.so.6 libmng.so.1 libpng12.so.0 libGLU.so.1 -y
- 安装开发工具
yum groupinstall "Development Tools"
- 安装leptonica1.7(4.0要修必须在1.74以上)
wget http://www.leptonica.org/source/leptonica-1.74.4.tar.gz
tar -xzvf leptonica-1.74.4.tar.gz
cd leptonica-1.74.4
./configure --prefix=/usr/local/
make && make install
配置环境
vim \etc\bashrc
加入
export PKG_CONFIG_PATH
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/include/
export CPLUS_INCLUDE_PATH
C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/leptonica/include/leptonica
export C_INCLUDE_PATH
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib
export LIBRARY_PATH
TESSDATA_PREFIX=/root/tesseract/
export TESSDATA_PREFIX
回到tesseract目录,开始安装
./autogen.sh
./configure --with-extra-includes=/usr/local/include --with-extra-libraries=/usr/local/include
注:这时有可能会报 configure: error: Leptonica 1.74 or higher is required. Try to install libleptonica-dev package.
明明我们已经安装了的。为什么还会报呢?
那就要加入环境变量
vim /etc/profile
在最后插入
export LD_LIBRARY_PATH=$LD_LIBRARY_PAYT:/usr/local/lib
export LIBLEPT_HEADERSDIR=/usr/local/include
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
最后刷新下文件
source /etc/profile
然后我们再执行
./autogen.sh
./configure --with-extra-includes=/usr/local/include --with-extra-libraries=/usr/local/include
这时就没有 leptonica问题啦,随后make下
make && sudo make install
最后我们用代码测试一切都正常,但到项目中却莫明奇妙地失败,断点服务直接崩掉,cache不住,找不到报错
各种百度google最后确认下来可能少了tess4j要的linux依赖库
执行下
cp /usr/local/lib/*.so.* /usr/lib64/
如果报
Error in findTiffCompression: function not present
Error in pixReadStreamTiff: function not present
Error in pixReadStream: tiff: no pix returned
Error in pixRead: pix not read
Unsupported image type.
相关。
那就是没有少了png和jpge依赖库
yum install libjpeg-devel
yum install libpng-devel
进入leptonica的安装文件夹重新编译
./configure
make
make install
到此基本所有问题都 解决了。运行项目正常
来源:oschina
链接:https://my.oschina.net/u/4313588/blog/3511388