Mac环境编译安装tesseract-4.1.1

Mojave 编译安装 tesseract-4.1.1

前言

顺便学习下Python,尝试使用Python3安装tesseract进行文字识别,结果踩了好深一个坑,特此记念……

好多坑,好多坑……

参考彭世瑜的这一篇:https://blog.csdn.net/mouday/article/details/104398303

1、安装好多依赖

# Packages which are always needed.
brew install automake autoconf libtool
brew install pkgconfig
brew install icu4c
brew install leptonica

# 如果你需要用到训练工具,要安装 pango.
brew install pango

# Optional packages for extra features
brew install libarchive

# Optional package for builds using g++.
brew install gcc

2、下载并解压 tesseract-4.1.1.tar.gz

下载地址为:https://github.com/tesseract-ocr/tesseract/releases

Mac环境编译安装tesseract-4.1.1_第1张图片

3、进入安装阶段

我的直接解压到 /Users/Jacky/tesseract-4.1.1

cd tesseract-4.1.1
./autogen.sh
mkdir build
cd build

# 以下为执行我的配置,请各位按照自己的版本号进行设置

./configure cairo_LIBS=-L/usr/local/Cellar/cairo/1.16.0_3/lib cairo_CFLAGS=-I/usr/local/Cellar/cairo/1.16.0_3/include pango_LIBS=-L/usr/local/Cellar/pango/1.44.7/lib pango_CFLAGS=-I/usr/local/Cellar/pango/1.44.7/include/pango-1.0 icu4c_LIBS=-L/usr/local/Cellar/icu4c/64.2/lib icu4c_CFLAGS=-I/usr/local/Cellar/icu4c/64.2/include  CC=gcc-9 CXX=g++-9 CPPFLAGS='-I/usr/local/opt/icu4c/include -I/usr/local/Cellar/glib/2.64.1_1/include/glib-2.0 -I/usr/local/Cellar/glib/2.64.1_1/lib/glib-2.0/include -I/usr/local/Cellar/cairo/1.16.0_3/include/cairo -I/usr/local/Cellar/freetype/2.10.1/include/freetype2 -I/usr/local/Cellar/fontconfig/2.13.1/include' LDFLAGS='-L/usr/local/opt/icu4c/lib -L/usr/local/Cellar/giflib/5.2.1/lib -L/usr/local/Cellar/pango/1.44.7/lib -L/usr/local/Cellar/glib/2.64.1_1/lib -L/usr/local/Cellar/cairo/1.16.0_3/lib -L/usr/local/Cellar/fontconfig/2.13.1/lib' --prefix=/Users/Jacky/tesseract.4.1.1

make -j

# Optionally install Tesseract.
sudo make install

# Optionally build and install training tools.
make training

sudo make training-install

比如:/usr/local/Cellar/cairo/我的版本号为1.16.0_3
Mac环境编译安装tesseract-4.1.1_第2张图片还有一个需要注意的是gcc的版本号,这里我的为9

Mac环境编译安装tesseract-4.1.1_第3张图片

执行configure过程遇到的问题

configure: WARNING: pango 1.22.0 or higher is required, but was not found.
configure: WARNING: Training tools WILL NOT be built.
configure: WARNING: Try to install libpango1.0-dev package.
checking for cairo... no
configure: WARNING: Training tools WILL NOT be built because of missing cairo library.
configure: WARNING: Try to install libcairo-dev?? package.
checking that generated files are newer than configure... done

我的pango的版本已经是1.44.7,总是提示我pango 1.22.0 or higher is required
请按照上面的./configure 里的设置更改为自己的版本号

libcairo-dev也是需要在./configure里直接指定

cairo_LIBS=-L/usr/local/Cellar/cairo/1.16.0_3/lib
cairo_CFLAGS=-I/usr/local/Cellar/cairo/1.16.0_3/include
pango_LIBS=-L/usr/local/Cellar/pango/1.44.7/lib
pango_CFLAGS=-I/usr/local/Cellar/pango/1.44.7/include/pango-1.0 

接着你会遇到icu的问题……

然后各种搜索,mac没有icu,只有icu4c,可是我已经装了icu4c的
Mac环境编译安装tesseract-4.1.1_第4张图片漫长的搜索过程……

然后又安装了PyICU,又在bash_profile文件中加了一些路径

# 没搞懂为什么要装这个 pyicu
pip3 install pyicu

open ~/.bash_profile

# 增加了如下的路径
export PATH="/usr/local/opt/icu4c/bin:$PATH"
export PATH="/usr/local/opt/icu4c/sbin:$PATH"
export ICU_VERSION=64
export PYICU_INCLUDES=/usr/local/Cellar/icu4c/64.2/include
export PYICU_LFLAGS=-L/usr/local/Cellar/icu4c/64.2/lib
export PYICU_CFLAGS=-std=c++11
export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"

source ~/.bash_profile

总算是 .configure 通过了(注意,以上几个步骤我也不知道是哪个起作用了
Mac环境编译安装tesseract-4.1.1_第5张图片

你以为就可以make training了吗?

于是,我遇到了这个问题

在这里插入图片描述然后又经过无脑的搜索……

然后在这一篇上,百度快照上

发现

好吧,我懒……再次打开这个草稿时,已经是1年后了,所以上面的部分供参考了

你可能感兴趣的:(python,tesseract)