前言
最近要識別充值卡上的序號與密碼侧蘸,故出一篇訓(xùn)練Tesserct的教程捕儒。
下載安裝Tesseract
訪問github的 tesseract-ocr 下載windows下的安裝包(因筆者是在windows系統(tǒng)下作訓(xùn)練)
An unofficial installer for windows for Tesseract 3.05-dev and Tesseract 4.00-dev is available from Tesseract at UB Mannheim. This includes the training tools.An installer for the old version 3.02 is available for Windows from our download page. This includes the English training data. If you want to use another language, download the appropriate training data, unpack it using 7-zip, and copy the .traineddata file into the 'tessdata' directory, probably
C:\Program Files\Tesseract-OCR\tessdata
點擊上面的download轨功,我們來到了下載頁面:
Binaries for Windows
- 4.0.0: https://github.com/tesseract-ocr/tesseract/wiki/4.0-with-LSTM#400-alpha-for-windows
- 3.5.1: https://github.com/parrot-office/tesseract/releases/tag/3.5.1 (3rd party - @parrot-office)
選擇適合版本下載即可丰辣。
有關(guān)安裝和環(huán)境變量的配置乍恐,不在此多說默蚌,大家搜索就知道怎么配置了辆琅。
下載jTessBoxEditor
點我進(jìn)入官網(wǎng) 點擊左方的downlaod即可到下載頁面
將需要識別的圖片轉(zhuǎn)換為tif
有很多轉(zhuǎn)換工具漱办,選擇你喜歡的工具進(jìn)行轉(zhuǎn)換即可 ;或者直接用linux的(ImageMagick)mogrify 批量轉(zhuǎn)換格式
mogrify -path [exist_dir] -format tif *.png
合并tif文件
運行jTessBoxEditor,雙擊train.bat即可運行:
按下Ctrl+M婉烟,彈出合并選擇文件
選擇打開后會讓你選擇保存的位置:
我們保存為:num.font.exp10
生成box
tesseract num.font.exp10.tif num.font.exp10 -psm 10 digits batch.nochop makebox
注意:因為我的tif都是單字且為數(shù)字娩井,故加了
-psm 10 digits
,有關(guān)此選項的其他配置請搜索了解似袁。
修正識別錯誤的box
再次運行jTessBoxEditor洞辣,
發(fā)現(xiàn)6被識別成.了
點擊藍(lán)色的小圈,然后修改紅色箭頭的坐標(biāo)信息以及正確的字符值:6
修改后昙衅,記得點擊保存扬霜。
建立字體屬性文件
font 0 0 0 0 0
保存為:font_properties
生成tr信息
tesseract num.font.exp10.tif num.font.exp10 -psm 10 digits nobatch box.train
生成字體特征信息
unicharset_extractor num.font.exp10.box
shapeclustering -F font_properties -U unicharset num.font.exp10.tr
mftraining -F font_properties -U unicharset -O unicharset num.font.exp10.tr
cntraining num.font.exp10.tr
將得到的:unicharset、inttemp而涉、pffmtable著瓶、shapetable、normproto重命名為num.開頭
如:
最后執(zhí)行
combine_tessdata num.
得到訓(xùn)練信息num.traineddata