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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章