Linux安装OCR识别工具tesseract

参考博客:【工具类】Linux安装OCR识别工具tesseract - 简书

参考网站: https://github.com/tesseract-ocr/tessdata

1 安装依赖

yum install -y libpng-devel libjpeg-devel libtiff-devel

2 安装leptonica

下载leptonica-1.78,下载地址:http://www.leptonica.org/source/leptonica-1.78.0.tar.gz
解压并安装

tar -xzvf leptonica-1.78.0.tar.gz
cd leptonica-1.78.0
./configure
make && make install

 当./configure 报错,可以执行下面命令安装对应的环境

yum groupinstall "Development Tools"

安装完成后,配置环境变量
/etc/profile文件尾部添加

export LD_LIBRARY_PATH=/usr/local/lib
export LIBLEPT_HEADERSDIR=/usr/local/include
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

或者利用如下命令向 /etc/profile文件添加内容

echo "export LD_LIBRARY_PATH=/usr/local/lib" >> /etc/profile
echo "export LIBLEPT_HEADERSDIR=/usr/local/include" >> /etc/profile
echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig" >> /etc/profile

使配置立即生效

source /etc/profile

3 安装tesseract-ocr

下载tesseract-ocr4.0,下载地址:https://github.com/tesseract-ocr/tesseract/archive/5.3.2.tar.gz
解压并安装

https://github.com/tesseract-ocr/tesseract/archive/5.3.2.tar.gz
tar -xzf 5.3.2.tar.gz
cd tesseract-5.3.2
./autogen.sh
./configure
make && make install
ldconfig

下载OCR识别字符集

 https://github.com/tesseract-ocr/tessdata  语料包集合

cd /usr/local/share/tessdata
wget https://raw.githubusercontent.com/tesseract-ocr/tessdata/main/eng.traineddata
wget https://raw.githubusercontent.com/tesseract-ocr/tessdata/main/chi_sim.traineddata
wget https://raw.githubusercontent.com/tesseract-ocr/tessdata/main/chi_sim_vert.traineddata

测试tesseract-ocr4.0是否可用,分别输入tesseract --versiontesseracttesseract --list-langs,如果能出现如下界面,则说明tesseract安装成功。

4.可能遇到的错误

1.【错误描述】
错误描述如下

[root@localhost nsimtest]# tesseract --list-langs
Error opening data file /usr/local/share/tessdata/eng.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory.
Failed loading language 'eng'
Tesseract couldn't load any languages!

【解决方案】
如果出现该错误,说明在默认的字符集路径中,未找到任何可用的字符集,此时就需要手动下载字符集,可参考安装步骤3来下载字符集。

【解决方案】
如果出现该错误,说明在默认的字符集路径中,有字符集,但是字符集有问题,笔者出现这个错误是因为直接复制Github上的链接到服务器直接下载的,结果下载下来的字符集都是85k左右,刚开始还未注意到这个问题,浪费较多时间。重新根据安装步骤3来下载字符集即可。

异常字符集

2.【错误描述】
错误描述如下

(base) [root@izrj97vwjyj7pi6cg9jveez tesseract-4.0.0]# make && make install
make  all-recursive
make[1]: Entering directory `/root/tesseract-4.0.0'
Making all in src/arch
make[2]: Entering directory `/root/tesseract-4.0.0/src/arch'
make[3]: Entering directory `/root/tesseract-4.0.0/src/arch'
/bin/sh ../../libtool  --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I../..  -DNDEBUG -I../../src/ccstruct -I../../src/ccutil -I../../src/viewer  -I/usr/local/include/leptonica   -mavx -g -O2 -std=c++11 -MT libtesseract_avx_la-dotproductavx.lo -MD -MP -MF .deps/libtesseract_avx_la-dotproductavx.Tpo -c -o libtesseract_avx_la-dotproductavx.lo `test -f 'dotproductavx.cpp' || echo './'`dotproductavx.cpp
libtool: Version mismatch error.  This is libtool 2.4.6, but the
libtool: definition of this LT_INIT comes from libtool 2.4.2.
libtool: You should recreate aclocal.m4 with macros from libtool 2.4.6
libtool: and run autoconf again.
make[3]: *** [libtesseract_avx_la-dotproductavx.lo] Error 63
make[3]: Leaving directory `/root/tesseract-4.0.0/src/arch'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/root/tesseract-4.0.0/src/arch'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/tesseract-4.0.0'
make: *** [all] Error 2

【解决方案】
如果出现该错误,说明tesseract安装失败。

【解决方案】

解决方法很简单:

运行 autoreconf -ivf 即可。

3.【错误描述】
错误描述如下

checking how to hardcode library paths into programs... immediate
checking whether C++ compiler accepts -std=c++17... no
checking whether C++ compiler accepts -std=c++20... no
configure: error: Your compiler does not have the necessary C++17 support! Cannot proceed.

【解决方案】
如果出现该错误,说明gcc 版本较低需要更新gcc版本

【解决方案】

解决方法很简单:

sudo yum install devtoolset-8
scl enable devtoolset-8 bash
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值