1. Dependency installation:
1. Check centos version
#cat /etc/redhat-release
CentOS release 6.5 (Final)
2. Check make, gcc and g++ versions
#gcc --version
#g++ --version
gcc的当前版本编译tesseract4.1会出错,需要gcc更高的版本
3. Install make, gcc and g++
由于我的环境是内网环境,软件下载、安装步骤详见,[离线安装Linux包](https://blog.csdn.net/zhuan_long/article/details/126120770?spm=1001.2014.3001.5502)
4. Install dependent packages
Required dependent packages are: autoconf automake libtool libjpeg-devel libpng-devel libtiff-devel zlib-devel leptonica (above 1.67)
- If the dependent package is in .rpm format, use the following command to install
rpm -ivh 包名
- If the dependent package is in compressed package format, it needs to be decompressed first
# 解压
tar -zxvf 文件名
# 进入包文件夹
cd 文件名
# 执行以下命令,进行程序编译,安装
./autogen.sh
./configure
make
make install
5. Add leptonica to the environment variable
# 修改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
6. Install tesseract
tar -xzvf 4.1.0.tar.gz
cd tesseract-4.1.0
./autogen.sh
./configure
make
sudo make install 或make install
7. Configure tesseract environment variables
vim /etc/profile
# 添加以下字段:
PATH=$PATH:/usr/local/tesseract/bin
export PATH
export TESSDATA_PREFIX=/root/tessdata
export PATH=$PATH:$TESSDATA_PREFIX
# 刷新配置
source /etc/profile
8. Check the tesseract version after installation
# 查看tesseract版本
tesseract --version
# 可执行文件路径:
which tesseract
/usr/local/bin/tesseract
# 语言包的路径(目前空空如也):
/usr/local/share/tessdata
9. Copy the tessdata directory
Copy the tessdata directory under the software installation directory to the /usr/local/share/tessdata directory
10. Download the tesseract language pack
Download the tesseract language pack, and put the language pack in the /usr/local/share/tessdata directory.
When we experience it, we only need to download the English and Simplified Chinese language packs: eng.traineddata, chi_sim.traineddata, chi_sim_vert.traineddata
11. First experience of tesseract recognition
-
Experience English recognition first, eng_test.jpg is the English text picture we prepared, and eng_result.txt is the output result:
#tesseract eng_test.jpg eng_result --psm 7 -
Experience Chinese recognition again, chi_sim_test.jpg is the Chinese text picture we prepared, chi_sim_result.txt is the output result:
#tesseract chi_sim_test.jpg chi_sim_result -l chi_sim --psm 7 -
The following briefly introduces the commonly used parameters
-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.
- Note:
1. If the image resolution and gpi do not meet the requirements, a warning will be returned:
Tesseract Open Source OCR Engine v4.1.0 with Leptonica
Warning: Invalid resolution 0 dpi. Using 70 instead.
Solution: modify the image gpi and resolution, refer to Test picture test_picture3.jpg