[置顶] 【Tesseract-OCR】Tesseract训练中文字体识别

时间:2022-02-24 22:21:00

字体训练

我准备了一份含汉语7000字和大小写英文字母和数字的文档.如果你需要训练所有中文的话,请将所有docx文件内所有字改成你要训练的字体。然后转化成tif格式的图片。先转PDF,再用工具转tif各式。

步骤(转自tesseract的github)

1、Prepare training text.
准备你的训练文本

2、Render text to image + box file. (Or create hand-made box files for existing image data.)

将文本转为image+box文件.(如果你已经有image文件的话,只需要手动生成box文件)

3、Make unicharset file.
生成unicharset文件

4、Optionally make dictionary data.
有选择性的生成字典数据

5、Run tesseract to process image + box file to make training data set.
运行tesseract来处理之前的image+box文件生成一个训练数据集合

6、Run training on training data set.
在训练数据集合的基础上进行训练

7、Combine data files.
合并数据文件

如果是其他图片格式,将其转为tif格式。附上一个在线地址
http://cn.office-converter.com/Convert-to-TIF

使用之前安装jTessBoxEditor工具将多张图片合并为一张(菜单栏 Tools → Merge TIFF)。并按照格式 [lang].[fontname].exp[num] 重命名合并后的文件,这里我命名为 chi.fangzheng.exp0.tif。

PDF转jpg地址:
http://www.pdfdo.com/pdf-to-image.aspx

http://app.xunjiepdf.com/pdf2jpg

jpg再转tif

参考链接:http://www.jianshu.com/p/31afd7fc5813

http://www.cnblogs.com/samlin/p/Tesseract-OCR.html

批处理程序rem.bat:

echo Run Tesseract for Training..  
tesseract.exe num.font.exp0.tif num.font.exp0 nobatch box.train

echo Compute the Character Set..
unicharset_extractor.exe num.font.exp0.box
mftraining -F font_properties -U unicharset -O num.unicharset num.font.exp0.tr

echo Clustering..
cntraining.exe num.font.exp0.tr

echo Rename Files..
rename normproto num.normproto
rename inttemp num.inttemp
rename pffmtable num.pffmtable
rename shapetable num.shapetable

echo Create Tessdata..
combine_tessdata.exe num.