所需软件:
(1) Tesseract 3.00
(2) jTessBoxEditer,是一个java程序,安装之前需先安装jre。若不想装jre,也可以使用CowBoxer 1.01
主要是用于box文件编辑
生成第一个 box 文件
将 Tesseract 解压到了 E:\tesseract-ocr 目录。然后在该目录中建立了一个 build 目录用于存放原始数据和训练过程中生成的文件。原始图片数据一个有 3 个 (test.001.tif - test.003.tif,tif文件可使用jTessBoxEditer生成):
首先生成第一个图片 test.001.tif 的 box 文件,这里使用官方的 eng 语言数据进行文字识别:
E:\tesseract-ocr\build
>..\tesseract test.001.tif test.001
-l eng batch.nochop makebox
Tesseract Open Source OCR Engine with Leptonica
Number of found pages: 1.
Tesseract Open Source OCR Engine with Leptonica
Number of found pages: 1.
执行完这个命令之后,build 目录下就生成了一个 test.001.box。若使用 CowBoxer ,打开这个 box 文件,CowBoxer 会自动找到同名的 tif 文件显示出来。
CowBoxer 的使用方法可以看 Help -> About 中的说明。修改完成之后 File -> Save box file 保存文件。
若是使用jTessBoxEditer,也打开box文件,会自动加载同名的tif文件,然后对box文件进行编辑。主要是修改box文件中不正确的地方
包括字符本身、字符的位置等。因为之后会用box文件来训练,所以要保证box文件的正确。
修改完以后,同样保存box文件。
接下来使用这一个 box 文件先生成一个 traineddata,在接下来生成其他图片的 box 文件时,使用这个 traineddata 有利于提高识别的正确率,减少修改次数。
..\tesseract test.001.tif test.001 nobatch box.train
..\training\unicharset_extractor test.001.box
..\training\mftraining -U unicharset -O test.unicharset test.001.tr
..\training\cntraining test.001.tr
rename normproto test.normproto
rename Microfeat test.Microfeat
rename inttemp test.inttemp
rename pffmtable test.pffmtable
..\training\combine_tessdata test.
..\training\unicharset_extractor test.001.box
..\training\mftraining -U unicharset -O test.unicharset test.001.tr
..\training\cntraining test.001.tr
rename normproto test.normproto
rename Microfeat test.Microfeat
rename inttemp test.inttemp
rename pffmtable test.pffmtable
..\training\combine_tessdata test.
在 build 目录下执行完这一系列命令之后,就生成了可用的 test.traineddata。
生成其余 box 文件
将上一步生成的 test.traineddata 移动到 tesseract-ocr\tessdata 目录中,接下来生成其他 box 文件时就可以通过 -l test 参数使用它了。
..\tesseract test.002.tif test.002
-l
test batch.nochop makebox
..\tesseract test.003.tif test.003 -l test batch.nochop makebox
..\tesseract test.003.tif test.003 -l test batch.nochop makebox
这里仅仅是使用 3 个原始文件作为例子。实际制作训练文件时,什么时候生成一个 traineddata 根据情况而定。中途生成 traineddata 的目的只是为了提高文字识别的准确率,使后面生成的 box 文件能少做修改。
生成最终的 traineddata
在所有的 box 都制作完成后,就可以生成最终的 traineddata 了。
..\tesseract test.001.tif test.001 nobatch box.train
..\tesseract test.002.tif test.002 nobatch box.train
..\tesseract test.003.tif test.003 nobatch box.train
..\training\unicharset_extractor test.001.box test.002.box test.003.box
..\training\mftraining -U unicharset -O test.unicharset test.001.tr test.002.tr test.003.tr
..\training\cntraining test.001.tr test.002.tr test.003.tr
rename normproto test.normproto
rename Microfeat test.Microfeat
rename inttemp test.inttemp
rename pffmtable test.pffmtable
..\training\combine_tessdata test.
..\tesseract test.002.tif test.002 nobatch box.train
..\tesseract test.003.tif test.003 nobatch box.train
..\training\unicharset_extractor test.001.box test.002.box test.003.box
..\training\mftraining -U unicharset -O test.unicharset test.001.tr test.002.tr test.003.tr
..\training\cntraining test.001.tr test.002.tr test.003.tr
rename normproto test.normproto
rename Microfeat test.Microfeat
rename inttemp test.inttemp
rename pffmtable test.pffmtable
..\training\combine_tessdata test.
在文件较多时可以用程序生成这种脚本执行。