關於tesseract的訓練步驟流程,jTessBoxEditor工具的使用請移步:
https://blog.csdn.net/Hu_helloworld/article/details/100030283
以下是腳本的簡單介紹:
輸入的文件名
src:是字庫文件名,如nomal
font_name:字體名,如 num
desc:nomal.num.exp0
腳本使用時的目錄結構:
training├── jTessBoxEditor |——jTessBoxEditor.jar
├── nomal.num.exp0.tif
├── training.bat
注意:應先用jTessBoxEditor,合併樣本生成.tif文件,再使用腳本開始訓練,使用期間會再次打開jTessBoxEditor工具,便於調整字符位置和內容。應保證jTessBoxEditor 和 java環境正常。
@echo off
set "src=%1%"
set "font_name=%2%"
set "desc=%3%"
if not defined src set /p src=" please pass your filename: "
if not defined font_name set /p font_name=" please pass your font_name: "
if not defined desc set /p desc=" please pass your desc: "
rem 判斷參數的合法性
if not defined src echo IllegalArgumentException arg1 must not be null & pause>nul & exit
if not defined font_name echo IllegalArgumentException arg2 must not be null & pause>nul & exit
if not defined desc set "desc=%src:~0,-4%"
echo desc %desc%
rem 如果目錄下沒有font_properties 文件創建 font_properties ,並寫入文件
if exist font_properties (
echo font_properties exist
) else (
ECHO %font_name% 0 0 0 0 0 >"font_properties"
)
rem 刪除原有文件
if exist %font_name%.unicharset ECHO DEL %font_name%.unicharset & DEL /Q names %font_name%.unicharset
if exist %font_name%.inttemp ECHO DEL %font_name%.inttemp & DEL /Q names %font_name%.inttemp
if exist %font_name%.pffmtable ECHO DEL %font_name%.pffmtable & DEL /Q names %font_name%.pffmtable
if exist %font_name%.shapetable ECHO DEL %font_name%.shapetable & DEL /Q names %font_name%.shapetable
if exist %font_name%.normproto ECHO DEL %font_name%.normproto & DEL /Q names %font_name%.normproto
if exist %font_name%.font_properties ECHO DEL %font_name%.font_properties & DEL /Q names %font_name%.font_properties
rem 生成.box文件 可修改原始字庫eng
tesseract %desc%.tif %desc% -l eng --psm 6 batch.nochop makebox
ECHO Create files: %desc%.box
java -Xms128m -Xmx512m -jar jTessBoxEditor/jTessBoxEditor.jar
ECHO Please change your results , and press any key to continue
pause>nul
rem 生成.tr訓練文件
tesseract %desc%.tif %desc% nobatch box.train
rem 生成字符集文件 unicharset
unicharset_extractor %desc%.box
rem 生成shape文件,會生成shapetable 和 zwp.unicharset兩個文件
shapeclustering -F font_properties -U unicharset -O %src%.unicharset %desc%.tr
mftraining -F font_properties -U unicharset -O %src%.unicharset %desc%.tr
cntraining %desc%.tr
rem 配置新文件
rem if exist unicharset ECHO rename unicharset %font_name%.unicharset & rename unicharset %src%.unicharset
if exist inttemp ECHO rename inttemp %font_name%.inttemp & rename inttemp %src%.inttemp
if exist pffmtable ECHO rename pffmtable %font_name%.pffmtable & rename pffmtable %src%.pffmtable
if exist shapetable ECHO rename shapetable %font_name%.shapetable & rename shapetable %src%.shapetable
if exist normproto ECHO rename normproto %font_name%.normproto & rename normproto %src%.normproto
combine_tessdata %src%.
rem if exist font_properties ECHO rename font_properties %font_name%.font_properties & rename font_properties %font_name%.font_properties
ECHO press any key to continue
pause>nul
將代碼命名爲 XXX.bat,cmd cd 到訓練目錄執行。
可輸出腳本運行信息到logs.txt中:
training>>logs.txt
後期儘量再腳本中完善
腳本中一些訓練參數,路徑之類的可能有問題,腳本也很簡單,可以自己修改。
關於tesseract的訓練步驟流程、jTessBoxEditor工具的使用,請移步:
https://blog.csdn.net/Hu_helloworld/article/details/100030283