Tesseract 3.05.01 文字训练流程

前提:由于最近在做图片识别,所以做了自己的文字训练库,在网上找了许多博客,也走过了很多坑,庆幸最终完成了文字库的制作,为了不忘记,在此做记录。

必要条件:需要安装好tesseract ,并且已经有基本的中文字库,因为训练字库时需要用到。

重要提醒:以下所有命令均在训练库文件夹下执行的cmd.exe中执行。

  • 创建训练库文件夹,并放入一些需要训练的图片。

这里可以放入.png、.jpg、.tif等文件格式的图片。

  • 合并所有训练图片为一个.tif,使用工具TiffToy。

下载地址:https://dl.pconline.com.cn/download/1880758.html

使用时,注意选择图片格式;注意合并后的TIFF文件的路径默认在选择的文件夹的同等级目录下,而非在选择的文件夹内。生成的图片需要是tif格式。

执行后生成文件:****.tif

  • 生成box文件。

命令:

tesseract chi.sim.exp0.tif chi.sim.exp0 -l chi_sim -psm 7 batch.nochop makebox

执行后生成文件:chi.sim.exp0.box。

  • 修改box文件

主要是对前面****.tif的修改,需要用到jTessBoxEditor工具,下载链接忘记了,如果你需要给我留言,我看到就会给你发工具。

选择Box Editor -> Open,打开前文生成的文件****.tif。

红色方框即为当前选择的字,通过Character来修改,点击齿轮保存单个文字的修改,通过Save保存一张图片修改。

常用button的解释:

  1. Insert:在选定的文字框后面,插入一个文字框;
  2. Delete:删除选定的文字框。
  3. Character:需要修改的字;X增大文字框右移,减小文字框左移;Y增大文字框下移,减小文字框上移;W增加文字框宽度增加,减小文字框宽度减小;H增加文字框高度增加,减小文字框高度减小;修改后点击齿轮保存当前修改的字。
  4. Reload:当文字修改错误时,选择Reload,会重新下载当前修改的图片。
  5. Save:修改完成后,点击保存。
  6. Page:页码,当前修改的页码。
  7. 其他暂未使用,若后续用到,再来补充。如有小伙伴知晓,也可告知。
  • 编写font_properties。

font_properties是普通的txt文件去掉扩展名.txt,然后把下面这句话写入即可。

chisimggq是最后的字库名称,可以自行填写。0代表格式,暂时没有用过,如需设置请自行搜索设置。

font_properties 内的内容:

chisimggq 0 0 0 0 0

执行后生成:font_properties。

  • 生成训练文件

命令:

tesseract chi.sim.exp0.tif chi.sim.exp0 -l chi_sim -psm 7 nobatch box.train

有一些错误提示:(可暂时不作处理,博主不知道会带来什么影响)

FAIL!
APPLY_BOXES: boxfile line 3/鍗?((84,54),(109,79)): FAILURE! Couldn't find a matching blob

执行后生成:chi.sim.exp0.tr

  • 生成字符集文件

命令:

unicharset_extractor chi.sim.exp0.box

执行后生成:unicharset

  • 生成shape文件

命令:

shapeclustering -F font_properties -U unicharset -O unicharset chi.sim.exp0.tr

异常提示:(打印内容不完整,被我删除了一部分)

Reading chi.sim.exp0.tr ...
Bad properties for index 3, char 2: 0,255 0,255 0,0 0,0 0,0
Bad properties for index 4, char 0: 0,255 0,255 0,0 0,0 0,0
Bad properties for index 5, char 1: 0,255 0,255 0,0 0,0 0,0
Bad properties for index 6, char 5: 0,255 0,255 0,0 0,0 0,0
Bad properties for index 7, char 骞? 0,255 0,255 0,0 0,0 0,0
Bad properties for index 8, char 鍥? 0,255 0,255 0,0 0,0 0,0
Bad properties for index 9, char 杩? 0,255 0,255 0,0 0,0 0,0
Bad properties for index 10, char 鎴? 0,255 0,255 0,0 0,0 0,0
Bad properties for index 11, char 杩? 0,255 0,255 0,0 0,0 0,0
Bad properties for index 12, char 搴? 0,255 0,255 0,0 0,0 0,0
Bad properties for index 13, char 璐? 0,255 0,255 0,0 0,0 0,0
Bad properties for index 14, char 鍙? 0,255 0,255 0,0 0,0 0,0
Bad properties for index 15, char 鏀? 0,255 0,255 0,0 0,0 0,0
Building master shape table
Computing shape distances...
Stopped with 0 merged, min dist 999.000000
Computing shape distances...
Stopped with 0 merged, min dist 999.000000
Computing shape distances...
Stopped with 0 merged, min dist 999.000000
Computing shape distances... 0
Stopped with 0 merged, min dist 999.000000
Computing shape distances... 0
Stopped with 0 merged, min dist 999.000000
Computing shape distances... 0
Stopped with 0 merged, min dist 999.000000
Computing shape distances... 0
Stopped with 0 merged, min dist 999.000000
Computing shape distances... 0
Stopped with 0 merged, min dist 999.000000
Computing shape distances... 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
Stopped with 0 merged, min dist 0.084337
Master shape_table:Number of shapes = 135 max unichars = 1 number with multiple unichars = 0

执行后生成:shapetable

  • 生成聚集字符特征文件

命令:

mftraining -F font_properties -U unicharset -O unicharset chi.sim.exp0.tr

异常警告:

Bad properties for index 135, char 浜? 0,255 0,255 0,0 0,0 0,0
Bad properties for index 136, char :: 0,255 0,255 0,0 0,0 0,0
Bad properties for index 137, char .: 0,255 0,255 0,0 0,0 0,0
Bad properties for index 138, char 鐔? 0,255 0,255 0,0 0,0 0,0
Bad properties for index 139, char 鏈? 0,255 0,255 0,0 0,0 0,0
Warning: no protos/configs for Joined in CreateIntTemplates()
Warning: no protos/configs for |Broken|0|1 in CreateIntTemplates()
Warning: no protos/configs for ` in CreateIntTemplates()
Warning: no protos/configs for 鐏?in CreateIntTemplates()
Done!

执行后生成文件:pffmtable、inttemp。

  • 生成字符正常化特征文件

命令:

cntraining chi.sim.exp0.tr

执行后生成文件:normproto。

  • 更名

命令:(5条命令依次输入)

rename normproto chisimggq.normproto
rename inttemp chisimggq.inttemp
rename pffmtable chisimggq.pffmtable
rename unicharset chisimggq.unicharset
rename shapetable chisimggq.shapetable

执行后生成chisimggq.normproto、chisimggq.inttemp、chisimggq.pffmtable、chisimggq.unicharset、chisimggq.shapetable。

  • 合并训练文件

命令:

combine_tessdata chisimggq

执行后生成:chisimggq.traineddata(这个就是我们的文字库)

  • 验证

把生成的字库放入到字库目录下,才能进行调用验证。

命令:

tesseract 28.tif output -l chisimggq

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值