Training Tesseract – Make Box Files - kana112233/tesseract GitHub Wiki


For training Neural net based LSTM Tesseract 4.00 see Training Tesseract 4.00


注意:以下说明适用于旧版 3.0x版本的Tesseract.

##制作盒子文件

对于Run Tesseract for Training步骤,Tesseract需要一个“盒子”文件来与每个培训图像一起使用 . 盒子文件是一个文本文件,按顺序列出训练图像中的字符,每行一个,带有图像周围边界框的坐标. Tesseract 3.0有一种模式,它将输出所需格式的文本文件,但如果字符集与其当前训练不同,则自然会使文本不正确. 所以这里的关键过程是手动编辑文件以在其中放入正确的字符.

Run Tesseract on each of your training images using this command line:

tesseract [lang].[fontname].exp[num].tif [lang].[fontname].exp[num] batch.nochop makebox

e.g.

tesseract eng.timesitalic.exp0.tif eng.timesitalic.exp0 batch.nochop makebox

现在困难的部分. 您必须编辑文件[lang].[fontname] .exp [num] .box并将每个字符的UTF-8代码放在每行开头的文件中,代替放在那里的错误字符 通过Tesseract. 示例:分发包括图像eurotext.tif. 运行上面的命令会生成一个包含以下行的文本文件(第141-154行):

s 734 494 751 519 0
p 753 486 776 518 0
r 779 494 796 518 0
i 799 494 810 527 0
n 814 494 837 518 0
g 839 485 862 518 0
t 865 492 878 521 0
u 101 453 122 484 0
b 126 453 146 486 0
e 149 452 168 477 0
r 172 453 187 476 0
d 211 451 232 484 0
e 236 451 255 475 0
n 259 452 281 475 0

由于Tesseract以英语模式运行,因此无法正确识别变音符号. 需要使用支持UTF-8的编辑器更正此字符. 在这种情况下,u需要更改为ü.

支持UTF-8的推荐编辑器:Notepad ++,gedit,KWrite,Geany,Vim,Emacs,Atom,TextMate,Sublime Text. 选一个! Linux和Windows都有一个字符映射,可用于复制无法键入的字符.

理论上,box文件中的每一行都应该代表训练文件中的一个字符,但是如果你有一个横向破坏的字符,例如较低的双引号“它可能有2个盒子需要合并!

示例:第116-129行:

D 101 504 131 535 0
e 135 502 154 528 0
r 158 503 173 526 0
, 197 498 206 510 0
, 206 497 214 509 0
s 220 501 236 526 0
c 239 501 258 525 0
h 262 502 284 534 0
n 288 501 310 525 0
e 313 500 332 524 0
l 336 501 347 534 0
l 352 500 363 532 0
e 367 499 386 524 0
” 389 520 407 532 0

如您所见,低双引号字符表示为两个单引号. 必须按如下方式合并边界框:    *第一个数字(左)取两条线的最小值(197)    *第二个数字(下)取两条线的最小值(497)    *第三个数字(右)取两条线的最大值(214)    *第四个数字(上)取两条线的最大值(510)

这给出了:

D 101 504 131 535 0
e 135 502 154 528 0
r 158 503 173 526 0
„ 197 497 214 510 0
s 220 501 236 526 0
c 239 501 258 525 0
h 262 502 284 534 0
n 288 501 310 525 0
e 313 500 332 524 0
l 336 501 347 534 0
l 352 500 363 532 0
e 367 499 386 524 0
” 389 520 407 532 0

如果您没有成功地将训练图像上的字符分隔开,则可能会将某些字符连接到一个框中. 在这种情况下,您可以使用更好的间距重新制作图像并重新开始,或者如果该对是常见的,则将两个字符放在行的开头,使边界框代表它们. (截至3.00,“字符”的描述限制为24个字节.这将允许您使用6到24个unicode来描述字符,具体取决于您的代码在unicode集中的位置.如果有人点击此 限制,请提出描述您情况的问题.)

注意框文件中使用的坐标系在左下角有(0,0).

每行的最后一个数字是多页tiff文件中该字符的页码(从0开始).

有几个用于编辑框文件的可视化工具 - 请检查AddOns wiki.

###引导一个新的字符集

If you are trying to train a new character set, it is a good idea to put in the effort on a single font to get one good box file, run the rest of the training process, and then use Tesseract in your new language to make the rest of the box files as follows:

tesseract [lang].[fontname].exp[num].tif [lang].[fontname].exp[num] -l yournewlanguage batch.nochop makebox

This should make the 2nd box file easier to make, as there is a good chance that Tesseract will recognize most of the text correctly. You can always iterate this sequence adding more fonts to he training set (i.e. to the command line of mftraining and cntraining below) as you make them, but note that there is no incremental training mode that allows you to add new training data to existing sets. This means that each time you run mftraining and cntraining you are making new data files from scratch from the tr files you give on the command line, and these programs cannot take an existing intproto / pffmtable / normproto and add to them directly.

###提供Tif/Box对!

这些语言的SourceForge下载存档中提供了Tif/Box文件对:

荷兰

英文版

法国

德国

德国fraktur

意大利

西班牙文

注意tiff文件是G4压缩的

为了节省空间,所以你必须先拥有libtiff或解压缩它们.