分类
大小:103.6 MB
语言:简体中文系统:WinXP, Win2003, Vista, Win7, Win8, Win10
类别:文件管理时间:2018-08-21
jTessBoxEditor是一款专业的orc样本识别训练软件,基于java开发而来,可以进行Tesseract3.02.02样本训练,形成自己的语言库,提高验证码识别率和准确率,比较常用的就是验证码识别方面。有需要的朋友可以下载!
1)、准备样本图片
手动刷新某网站验证码,手动或者写程序,保存了101个验证码样本文件,分别命名成:1.png,2.png,……,101.png。
该验证码有几个特点:a、定长4位,b、都是数字,c、有背景干扰,但比较简单,d、字体为红色。
为了提高识别率,首先做了一个工作就是灰度化处理,并全部转换成tif文件,分别命名成:1.tif,2.tif,……,101.tif,统一存放在d:\python\lnypcg下。
2)、合并样本图片
打开jtessboxeditor,点击Tools->Merge Tiff ,按住shift键选择前文提到的101个tif文件,并把生成的tif合并到新目录d:\python\lnypcg\new下,命名为langyp.fontyp.exp0.tif。
注意:langyp 是本人定义的语言名称,fontyp是本人定义的字体名称,后续都会用到,你可以修改成你喜欢的名字。
3)、生成box文件
执行命令生成langyp.fontyp.exp0.box 文件
tesseract langyp.fontyp.exp0.tif langyp.fontyp.exp0 -l eng -psm 7 batch.nochop makebox
D:/python/lnypcg/new>tesseract langyp.fontyp.exp0.tif langyp.fontyp.exp0 -l eng -psm 7 batch.nochop makeboxTesseract Open Source OCR Engine v3.02 with LeptonicaPage 1 of 101Page 2 of 101Page 3 of 101……Page 101 of 101D:/python/lnypcg/new>dir 驱动器 D 中的卷没有标签。 卷的序列号是 36D9-CDC7 D:/python/lnypcg/new 的目录2016-06-03 14:37
.2016-06-03 14:37
..2016-06-03 14:30 6,327 langyp.fontyp.exp0.box 2016-06-03 13:07 126,056 langyp.fontyp.exp0.tif 2 个文件 132,383 字节 2 个目录 24,869,994,496 可用字节
4)、修改box文件
切换到jTessBoxEditor工具的Box Editor页,点击open,打开前面的tiff文件langyp.fontyp.exp0.tif,工具会自动加载对应的box文件。
检查box数据,如下图所示,数字8被误认成字母H,手工修改H成8,并保存。
点击下图红色框的按钮,逐个核对tif文件的box数据,全部检查结束并保存。
5)、生成font_properties
执行echo命令生成font_properties。
echo fontyp 0 0 0 0 0 >font_properties
也可以手工新建一个名为font_properties的文本文件(注意该文件没有扩展名),内容为字体名fontyp,后面带5个0,分别代表字体的粗体、斜体等属性,这里全部是0
D:/python/lnypcg/new>echo fontyp 0 0 0 0 0 >font_propertiesD:/python/lnypcg/new>type font_propertiesfontyp 0 0 0 0 0
6)、生成训练文件
执行命令,生成langyp.fontyp.exp0.tr训练文件
tesseract langyp.fontyp.exp0.tif langyp.fontyp.exp0 -l eng -psm 7 nobatch box.train
D:/python/lnypcg/new>tesseract langyp.fontyp.exp0.tif langyp.fontyp.exp0 -l eng -psm 7 nobatch box.trainTesseract Open Source OCR Engine v3.02 with LeptonicaPage 1 of 101row xheight=8.66667, but median xheight = 10APPLY_BOXES: Boxes read from boxfile: 4Found 4 good blobs.Generated training data for 1 words………………Page 101 of 101row xheight=8.66667, but median xheight = 10APPLY_BOXES: Boxes read from boxfile: 4 Found 4 good blobs.Generated training data for 1 words D:/python/lnypcg/new 的目录2016-06-03 16:34
.2016-06-03 16:34
..2016-06-03 16:05 16 font_properties2016-06-03 14:30 6,327 langyp.fontyp.exp0.box2016-06-03 13:07 126,056 langyp.fontyp.exp0.tif2016-06-03 16:20 618,844 langyp.fontyp.exp0.tr 2016-06-03 16:20 202 langyp.fontyp.exp0.txt 5 个文件 751,445 字节 2 个目录 24,869,101,568 可用字节
7)、生成字符集文件
执行命令,生成名为unicharset的字符集文件。
unicharset_extractor langyp.fontyp.exp0.box
D:/python/lnypcg/new>unicharset_extractor langyp.fontyp.exp0.boxExtracting unicharset from langyp.fontyp.exp0.boxWrote unicharset file ./unicharset.D:/python/lnypcg/new>dir 驱动器 D 中的卷没有标签。 卷的序列号是 36D9-CDC7 D:/python/lnypcg/new 的目录2016-06-03 16:41
.2016-06-03 16:41
..2016-06-03 16:05 16 font_properties2016-06-03 14:30 6,327 langyp.fontyp.exp0.box2016-06-03 13:07 126,056 langyp.fontyp.exp0.tif2016-06-03 16:20 618,844 langyp.fontyp.exp0.tr2016-06-03 16:20 202 langyp.fontyp.exp0.txt2016-06-03 16:41 712 unicharset 6 个文件 752,157 字节 2 个目录 24,869,171,200 可用字节
8)、生成shape文件
执行命令,生成shape文件
shapeclustering -F font_properties -U unicharset -O langyp.unicharset langyp.fontyp.exp0.tr
D:/python/lnypcg/new>shapeclustering -F font_properties -U unicharset -O langyp.unicharset langyp.fontyp.exp0.trReading langyp.fontyp.exp0.tr ...Building master shape tableComputing shape distances...Stopped with 0 merged, min dist 999.000000Computing shape distances... 0Stopped with 0 merged, min dist 999.000000Computing shape distances... 0Stopped with 0 merged, min dist 999.000000Computing shape distances... 0Stopped with 0 merged, min dist 999.000000Computing shape distances... 0Stopped with 0 merged, min dist 999.000000Computing shape distances... 0Stopped with 0 merged, min dist 999.000000Computing shape distances... 0Stopped with 0 merged, min dist 999.000000Computing shape distances... 0Stopped with 0 merged, min dist 999.000000Computing shape distances... 0Stopped with 0 merged, min dist 999.000000Computing shape distances... 0Stopped with 0 merged, min dist 999.000000Computing shape distances... 0Stopped with 0 merged, min dist 999.000000Computing shape distances... 0Stopped with 0 merged, min dist 999.000000Computing shape distances...Stopped with 0 merged, min dist 999.000000Computing shape distances...Stopped with 0 merged, min dist 999.000000Computing shape distances... 0 1 2 3 4 5 6 7 8 9 10Stopped with 0 merged, min dist 0.057803Master shape_table:Number of shapes = 11 max unichars = 1 number with multiple unichars = 0D:/python/lnypcg/new>dir 驱动器 D 中的卷没有标签。 卷的序列号是 36D9-CDC7 D:/python/lnypcg/new 的目录2016-06-03 17:24
.2016-06-03 17:24
..2016-06-03 17:20 19 font_properties2016-06-03 14:30 6,327 langyp.fontyp.exp0.box2016-06-03 13:07 126,056 langyp.fontyp.exp0.tif2016-06-03 17:23 618,844 langyp.fontyp.exp0.tr2016-06-03 17:23 202 langyp.fontyp.exp0.txt2016-06-03 17:24 723 langyp.unicharset2016-06-03 17:24 202 shapetable 2016-06-03 17:24 712 unicharset 8 个文件 753,085 字节 2 个目录 24,868,278,272 可用字节
9)、生成聚集字符特征文件
执行命令,生成3个特征字符文件,unicharset、inttemp、pffmtable
mftraining -F font_properties -U unicharset -O langyp.unicharset langyp.fontyp.exp0.tr
D:/python/lnypcg/new>mftraining -F font_properties -U unicharset -O langyp.unicharset langyp.fontyp.exp0.trRead shape table shapetable of 11 shapesReading langyp.fontyp.exp0.tr ...Done!
10)、生成字符正常化特征文件
执行命令,生成正常化特征文件normproto。
cntraining langyp.fontyp.exp0.tr
D:/python/lnypcg/new>cntraining langyp.fontyp.exp0.trReading langyp.fontyp.exp0.tr ...Clustering ...
11)、更名
执行命令,把步骤9,步骤10生成的特征文件进行更名。
rename normproto fontyp.normproto
rename inttemp fontyp.inttemp
rename pffmtable fontyp.pffmtable
rename unicharset fontyp.unicharset
rename shapetable fontyp.shapetable
D:/python/lnypcg/new>rename normproto fontyp.normprotoD:/python/lnypcg/new>rename inttemp fontyp.inttempD:/python/lnypcg/new>rename pffmtable fontyp.pffmtableD:/python/lnypcg/new>rename unicharset fontyp.unicharsetD:/python/lnypcg/new>rename shapetable fontyp.shapetable
12)、合并训练文件
执行命令,生成fontyp.traineddata文件。
combine_tessdata fontyp.
注意:
a、fontyp.traineddata文件最终要拷贝tesseract安装目录的tessdata目录下,才能被tesseract找到。
b、命令行最后必须带一个点。
c、执行结果中,1,3,4,5,13这几行必须有数值,才代表命令执行成功。
D:/python/lnypcg/new>combine_tessdata fontyp.Combining tessdata filesTessdataManager combined tesseract data files.Offset for type 0 is -1Offset for type 1 is 140 Offset for type 2 is -1Offset for type 3 is 852Offset for type 4 is 137760Offset for type 5 is 137850 Offset for type 6 is -1Offset for type 7 is -1Offset for type 8 is -1Offset for type 9 is -1Offset for type 10 is -1Offset for type 11 is -1Offset for type 12 is -1Offset for type 13 is 139352 Offset for type 14 is -1Offset for type 15 is -1Offset for type 16 is -1
13)测试使用
譬如前文的28.tif中8被误认为字母S,用新的字体看是否还出错。
D:/python/lnypcg>tesseract 28.tif output -l eng -psm 7Tesseract Open Source OCR Engine v3.02 with LeptonicaD:/python/lnypcg>type output.txtS094#1调用默认的eng语言,8被识别成S D:/python/lnypcg>tesseract 28.tif output -l fontyp -psm 7Error opening data file C:/Program Files (x86)/Tesseract-OCR/tessdata/fontyp.traineddataPlease make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory.Failed loading language 'fontyp'Tesseract couldn't load any languages!Could not initialize tesseract.#2条用新的fontyp语言,tesseract找不到fontyp语言。 D:/python/lnypcg>copy ./new/fontyp.traineddata "C:/Program Files (x86)/Tesseract-OCR/tessdata"已复制 1 个文件。#3复制 fontyp.traineddata到tesseract的安装目录的tessdata子目录下 D:/python/lnypcg>tesseract 28.tif output -l fontyp -psm 7Tesseract Open Source OCR Engine v3.02 with LeptonicaD:/python/lnypcg>type output.txt8094
#使用fontyp语言成功识别8094
展开