MacTesseract4.1.1样本训练超详细教程
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
MacTesseract4.1.1样本训练超详细教程
Mac Tesseract 4.1.1 样本训练超详细教程
乔布斯的橘⼦ 2021-03-17 01:40:17 483 收藏 2
⽂章标签: opencv python 图像识别 ocr
版权
安装
Mac直接安装tesseract的话⽆法附带安装training tools
如果已经安装了没有training tools的tesseract,请先卸载
brew uninstall tesseract
先安装⼀些依赖的包
# Packages which are always needed.
brew install automake autoconf libtool
brew install pkgconfig
brew install icu4c
brew install leptonica
# Packages required for training tools.
brew install pango
# Optional packages for extra features.
brew install libarchive
# Optional package for builds using g++.
brew install gcc
从下列链接下载tesseract-4.1.1.tar.gz并解压
编译并安装
cd tesseract-4.1.1
./autogen.sh
mkdir build
cd build
# Optionally add CXX=g++-8 to the configure command if you really want to use a different compiler.
../configure PKG_CONFIG_PATH=/usr/local/opt/icu4c/lib/pkgconfig:/usr/local/opt/libarchive/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig make -j
# Optionally install Tesseract.
sudo make install
# Optionally build and install training tools.
make training
sudo make training-install
下载完不会附带着⼀起下载数据集,通过下列链接⾃⾏下载需要的语⾔
训练
⾸先,收集数据样本(若⼲张需要训练的图⽚)
图⽚格式需要转换为tif
下载并打开jTessBoxEditor (注意,该软件需要java8环境,请⾃⾏配置):
在jTessBoxEditor中Tools->Merge TIFF将所有tif⽂件合并
将合并后的tif⽂件重命名为eng.num.exp0.tif
⽣成box⽂件,⽤来纠正识别错误
tesseract eng.num.exp0.tif eng.num.exp0 -l eng batch.nochop makebox
此时,应该有eng.num.exp0.tif和eng.num.exp0.box两个⽂件
使⽤jTessBoxEditor打开eng.num.exp0.tif
(Box Editor->Open->eng.num.exp0.tif)
纠正识别错误
新建⼀个⽂件,取名font_properties,并填⼊下列内容
font 0 0 0 0 0
执⾏如下命令训练数据
tesseract eng.num.exp0.tif eng.num.exp0 nobatch box.train unicharset_extractor eng.num.exp0.box
shapeclustering -F font_properties -U unicharset eng.num.exp0.tr mftraining -F font_properties -U unicharset -O unicharset eng.num.exp0.tr cntraining eng.num.exp0.tr
mv inttemp num.inttemp
mv normproto num.normproto
mv pffmtable num.pffmtable
mv shapetable num.shapetable
mv unicharset num.unicharset
combine_tessdata num.
执⾏后,会有如下⽂件
将num.traineddata移到相应路径便可使⽤
我的路径是/usr/local/share/tessdata/。