tesseract-ocr训练方法

来源:互联网 发布:女生学java有前途吗 编辑:程序博客网 时间:2024/04/29 05:53

http://blog.csdn.net/problc/article/details/8065011


tesseract-ocr训练方法

分类: C++ 5802人阅读 评论(2)收藏 举报
tiffpropertiescharactertraining语言merge

http://www.lixin.me/blog/2012/05/26/29536



tesseract-ocr有2和3两个版本,不同版本训练方法稍有不同。

第3版本的训练方法官版教程在这里:TrainingTesseract3

第2版的训练方法官版教程在这里:TrainingTesseract

我使用的是最新的3.01版本的。训练所需准备:

1.下载并安装3.01版本的tesseract。事实上并不需要安装这步骤,我下载的是压缩包版,解压即可,这里我解压到E:\Tesseract-ocr目录。

2.下载并安装jTessBoxEditor 工具,这是一个Box file editors,用来编辑训练文件的,直接下载地址在这里。这个软件是用java写的,运行需要安装jre,好在这个东西比.net好装多了,怎么运行可以见它的readme文件。

3.一张用来训练的tiff格式图片。

 

在不通过训练的前提下,使用tesseract来识别一个订单号的内容,如图1发现错误率很高,希望通过训练来提高准确率。

训练过程:

1.通过合并10张如上图的图片合并为一张tiff格式的图片,如何合并呢?通过jTessBoxEditor的Merge Tiff 来完成,不过他的小缺点就是只能合并多张tiff格式的,如果你的图片是jpg的,需要先转换。生成后的tiff图片叫做orderNo.tif

2.Make Box Files。在orderNo.tif所在的目录下打开一个命令行,输入:

E:\Tesseract-ocr\tesseract.exe orderNo.tif orderNo batch.nochop makebox

来生成一个box文件,该文件记录了tesseract识别出来的每一个字和其位置坐标。

3.使用jTessBoxEditor打开orderNo.tif文件,需要记住的是第2步生成的orderNo.box要和这个orderNo.tif文件同在一个目录下。逐个校正文字,后保存。

4.Run Tesseract for Training。输入命令:

E:\Tesseract-ocr\tesseract.exe orderNo.tif orderNo nobatch box.train

5.Compute the Character Set。输入命令:

E:\Tesseract-ocr\unicharset_extractor.exe orderNo.box

6.新建文件“font_properties”。如果是3.01版本,那么需要在目录下新建一个名字为“font_properties”的文件,并且输入文本 :

orderNo 0 0 0 0 0

大致意思就是说orderNo这个语言的字体为普通字体。

并执行命令:

E:\Tesseract-ocr\mftraining.exe -F font_properties -U unicharset orderNo.tr

7.Clustering。输入命令:

E:\Tesseract-ocr\cntraining.exe orderNo.tr

8.此时,在目录下应该生成若干个文件了,把unicharset, inttemp, normproto, pffmtable这四个文件加上前缀“orderNo.”。然后输入命令:

E:\Tesseract-ocr\combine_tessdata.exe orderNo.

会显示一个结果如:

Combining tessdata files
TessdataManager combined tesseract data files.
Offset for type 0 is -1
Offset for type 1 is 108
Offset for type 2 is -1
Offset for type 3 is 1660
Offset for type 4 is 327545
Offset for type 5 is 327781
Offset for type 6 is -1
Offset for type 7 is -1
Offset for type 8 is -1
Offset for type 9 is -1
Offset for type 10 is -1
Offset for type 11 is -1
Offset for type 12 is –1

必须确定的是第2、4、5、6行的数据不是-1,那么一个新的字典就算生成了。

此时目录下“orderNo.traineddata”的文件拷贝到tesseract程序目录下的“tessdata”目录。

以后就可以使用该该字典来识别了,例如:

tesseract.exe test.jpg result –l orderNo

 

通过训练出来的新语言,识别率提高了不少。


0 0
原创粉丝点击