#cat /etc/redhat-release
CentOS release 6.5 (Final)
#gcc --version
#g++ --version
gcc的当前版本编译tesseract4.1会出错,需要gcc更高的版本
由于我的环境是内网环境,软件下载、安装步骤详见,[离线安装Linux包](https://blog.csdn.net/zhuan_long/article/details/126120770?spm=1001.2014.3001.5502)
所需依赖包有:autoconf automake libtool libjpeg-devel libpng-devel libtiff-devel zlib-devel leptonica(1.67以上)
rpm -ivh 包名
# 解压
tar -zxvf 文件名
# 进入包文件夹
cd 文件名
# 执行以下命令,进行程序编译,安装
./autogen.sh
./configure
make
make install
# 修改profile
vim /etc/profile
# 添加信息
export LD_LIBRARY_PATH=/usr/local/lib
export LIBLEPT_HEADERSDIR=/usr/local/include
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
# 保存
# 刷新配置
source /etc/profile
tar -xzvf 4.1.0.tar.gz
cd tesseract-4.1.0
./autogen.sh
./configure
make
sudo make install 或make install
vim /etc/profile
# 添加以下字段:
PATH=$PATH:/usr/local/tesseract/bin
export PATH
export TESSDATA_PREFIX=/root/tessdata
export PATH=$PATH:$TESSDATA_PREFIX
# 刷新配置
source /etc/profile
# 查看tesseract版本
tesseract --version
# 可执行文件路径:
which tesseract
/usr/local/bin/tesseract
# 语言包的路径(目前空空如也):
/usr/local/share/tessdata
将软件安装目录下的tessdata目录拷贝到/usr/local/share/tessdata目录
下载tesseract语言包,把语言包放到/usr/local/share/tessdata目录下
我们体验的时候只要下载英文和简体中文语言包即可:eng.traineddata、chi_sim.traineddata、chi_sim_vert.traineddata
先体验英文识别,eng_test.jpg是我们准备的英文文字图片,eng_result.txt为输出结果:
#tesseract eng_test.jpg eng_result --psm 7
再体验一下中文识别,chi_sim_test.jpg是我们准备中文文字图片,chi_sim_result.txt为输出结果:
#tesseract chi_sim_test.jpg chi_sim_result -l chi_sim --psm 7
下面简单介绍一下常用的参数
-l参数表示要用的语言包,chi_sim表示简体中文语言包,默认为英文;
--psm参数可以简单理解成图片中的文字的布局方式,默认为:3
0 = Orientation and script detection (OSD) only.
1 = Automatic page segmentation with OSD.
2 = Automatic page segmentation, but no OSD, or OCR.
3 = Fully automatic page segmentation, but no OSD. (Default)
4 = Assume a single column of text of variable sizes.
5 = Assume a single uniform block of vertically aligned text.
6 = Assume a single uniform block of text.
7 = Treat the image as a single text line.
8 = Treat the image as a single word.
9 = Treat the image as a single word in a circle.
10 = Treat the image as a single character.