CentOS7 上编译安装 Tesseract 5.2.0
1、编译工具安装
yum install -y gcc gcc-c++ make autoconf automake libtool libjpeg libpng libtiff zlib libjpeg-devel libpng-devel libtiff-devel zlib-devel
2、升级gcc8(编译 Tesseract5 需要 c++17)
yum install -y centos-release-scl
yum install -y devtoolset-8-gcc*
mv /usr/bin/gcc /usr/bin/gcc-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/g++ /usr/bin/g++
查看版本是否安装成功
gcc -v
gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
g++ -v
g++ (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
3、安装 leptonica(Tesseract 依赖 leptonica 进行图片处理)
wget http://www.leptonica.org/source/leptonica-1.82.0.tar.gz
tar zxf leptonica-1.82.0.tar.gz
cd leptonica-1.82.0/
./configure && make && make install
编辑 /etc/profile 添加环境变量
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LIBLEPT_HEADERSDIR=/usr/local/include
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
使配置失效
source /etc/profile
4、编译安装 tesseract 5.2.0
wget https://github.com/tesseract-ocr/tesseract/archive/refs/tags/5.2.0.tar.gz
tar xvf 5.2.0.tar.gz
cd tesseract-5.2.0
./autogen.sh
./configure --with-extra-includes=/usr/local/include --with-extra-libraries=/usr/local/lib
sudo make && make install
完成后提示:
Libraries have been installed in:
/usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR’
flag during linking and do at least one of the following:add LIBDIR to the `LD_LIBRARY_PATH’ environment variable
during executionadd LIBDIR to the `LD_RUN_PATH’ environment variable
during linkinguse the `-Wl,-rpath -Wl,LIBDIR’ linker flaghave your system administrator add LIBDIR to `/etc/ld.so.conf’
完成后查看版本
tesseract -v
5、下载语言
cd /usr/local/share/tessdata/
wget https://github.com/tesseract-ocr/tessdata/raw/main/eng.traineddata
#这里下载的是 legacy 英文语言模型,也可以下载 fast 或 best 的
6、测试
tesseract 25.png output
执行后 output.txt 中就是 ocr 结果
版权声明:
作者:白纸画
链接:https://www.fanyicloud.cn/article-62.fan
来源:白纸画的博客
文章版权归作者所有,未经允许请勿转载。

全部评论