Linux下利用jTessBoxEditor工具进行Tesseract3.02.02样本训练


Linux下利用jTessBoxEditor工具进行Tesseract3.02.02样本训练


1.准备样本图片

为提高识别率,把图片进行灰度化处理,可以用

convert -monochrome name.png name.png
把图片变成黑白色

然后利用

convert name.jpg name.tif
命令,把其他类型的图片文件转换成.tif文件


2.合并样本图片

打开jtessboxeditor,点击Tools->Merge Tiff ,按住shift键选择tif文件,并把生成的tif命名为fontname.fonttype.exp0.tif


3.生成box文件

执行命令生成fontname.fonttype.exp0.box文件

tesseract   fontname.fonttype.exp0.tif    fontname.fonttype.exp0    
-l   eng  <span style="font-family: 'Open Sans', sans-serif; line-height: 2em;">-psm  3 </span><span style="line-height: 2em; font-family: 'Open Sans', sans-serif;">batch.nochop   makebox</span>



下面是-psm参数的大意,可以根据其选择对应的数

Usage:tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...]
pagesegmode values are:
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.
-l lang and/or -psm pagesegmode must occur before anyconfigfile .



4.修改box文件

切换到jTessBoxEditor工具的Box Editor页,点击open,打开前面的tiff文件fontname.fonttype.exp0.tif,工具会自动加载对应的box

检查box数据,逐个核对tif文件的box数据,全部修改结束并保存。


5.生成font_properties

执行echo命令生成font_properties。

echo fontyp 0 0 0 0 0 >font_properties

也可以手工新建一个名为font_properties的文本文件(注意该文件没有扩展名),内容为字体名fonttype,后面带5个0,分别代表字体的粗体、斜体等属性,这里全部是0


6.生成训练文件

执行命令,生成fontname.fonttype.exp0.tr训练文件

tesseract fontname.fonttype.exp0.tif fontname.fonttype.exp0 <span style="font-family: 'Open Sans', sans-serif; line-height: 2em;">-l eng -psm 3 nobatch box.train</span>
注意,里面的eng项可以根据实际情况修改  


7.生成字符集文件

执行命令,生成名为unicharset的字符集文件。

unicharset_extractor fontname.fonttype.exp0.box

8.生成shape文件

执行命令,生成shape文件

shapeclustering -F font_properties -U unicharset -O fontname.unicharset <span style="font-family: 'Open Sans', sans-serif; line-height: 2em;">fontname.fonttype.exp0.tr</span>



9.生成聚集字符特征文件

执行命令,生成3个特征字符文件,unicharset、inttemp、pffmtable

mftraining -F font_properties -U unicharset -O fontname.unicharset fontname.fonttype.exp0.tr



10.生成字符正常化特征文件

执行命令,生成正常化特征文件normproto。

cntraining fontname.fonttype.exp0.tr


11.更名

执行命令,把步骤9,步骤10生成的特征文件进行更名。

mv normproto fontname.normproto
mv inttemp fontname.inttemp
mv pffmtable fontname.pffmtable 
mv unicharset fontname.unicharset
mv shapetable fontname.shapetable

12.合并训练文件

执行命令,生成fontname.traineddata文件。

combine_tessdata fontname.

注意:

a、fontname.traineddata文件最终要拷贝tesseract安装目录的tessdata目录下,才能被tesseract找到。

b、命令行最后必须带一个点。

c、执行结果中,1,3,4,5,13这几行必须有数值,才代表命令执行成功。












  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值