linux安装tesseract

发布时间:2024年01月18日

tesseract又依赖于leptonica。需要先安装好tesseract与leptonica;

1、安装依赖环境

yum install autoconf automake libtool libjpeg-devel libpng-devel libtiff-devel zlib-devel gcc gcc-c++

2、下载安装包

tesseract包下载:https://github.com/tesseract-ocr/tesseract/releases/tag/5.3.3
leptonica包下载:http://www.leptonica.org/download.html

3、安装leptonica

安装

#解压
tar -zxvf leptonica-1.84.1.tar.gz
#进入leptonica文件夹
cd leptonica-1.84.1
#编译并安装到/usr/local/leptonica文件夹下
./configure --prefix=/usr/local/leptonica  && make  && make install

配置环境变量

vim /etc/profile

#在文件中追加下面内容
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/leptonica/lib/pkgconfig
export PKG_CONFIG_PATH
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/leptonica/include/leptonica
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/leptonica/lib
export LD_LIBRARY_PATH
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/leptonica/lib
export LIBRARY_PATH
LIBLEPT_HEADERSDIR=/usr/local/leptonica/include/leptonica
export LIBLEPT_HEADERSDIR

#环境变量生效
source /etc/profile

安装tesseract

安装

tar -zxvf tesseract-5.3.3.tar.gz
#进入tesseract文件夹
cd tesseract-5.3.3
# 必须先运行autogen.sh文件才会有configuer文件
./autogen.sh
# 编译安装到指定文件夹
./configure --prefix=/usr/local/tesseract  && make && make install

如果出现如下错误

configure: error: Leptonica 1.74 or higher is required. Try to install libleptonica-dev package.
然后更换如下执行命令
```java
./configure --prefix=/usr/local/tesseract --with-extra-includes=/usr/local/leptonica/include --with-extra-libraries=/usr/local/leptonica/lib && make && make install

如果执行出现如下错误

devanagari_processing.cpp:132:19: error: invalid use of incomplete type 'struct Pixa'
     Box* box = ccs->boxa->box[i];
                   ^
In file included from /usr/local/leptonica/include/leptonica/alltypes.h:52:0,
                 from /usr/local/leptonica/include/leptonica/allheaders.h:35,
                 from devanagari_processing.cpp:25:
/usr/local/leptonica/include/leptonica/bmf.h:48:12: error: forward declaration of 'struct Pixa'

则说明leptonica版本高了,升级tesseract到5.x版本
如果出现如下错误

configure: error: Your compiler does not have the necessary C++17 support! Cannot proceed.

则需要升级GCC版本

yum install -y centos-release-scl
yum install devtoolset-8-gcc*
#切换当前会话中gcc版本为8
scl enable devtoolset-8 bash

经过艰难的验证终于成功了,然后配置环境变量

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/leptonica/lib/pkgconfig
export PKG_CONFIG_PATH
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/leptonica/include/leptonica
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/leptonica/lib:/usr/local/tesseract/lib
export LD_LIBRARY_PATH
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/leptonica/lib:/usr/local/tesseract/lib
export LIBRARY_PATH
LIBLEPT_HEADERSDIR=/usr/local/leptonica/include/leptonica
export LIBLEPT_HEADERSDIR

PATH=$PATH:/usr/local/tesseract/bin
export PATH
export TESSDATA_PREFIX=/usr/local/tessdata   #训练库所在文件目录
export PATH=$PATH:$TESSDATA_PREFIX

测试

tesseract --version
文章来源:https://blog.csdn.net/u010833154/article/details/135633713
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。