溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

tesseract-ocr tips

發(fā)布時(shí)間:2020-04-04 09:25:05 來源:網(wǎng)絡(luò) 閱讀:1789 作者:RQSLT 欄目:開發(fā)技術(shù)

【基本用法】

1、tesseract 基本語法:

Usage:tesseract.exe p_w_picpathname outputbase [-l lang] [-psm pagesegmode] [configfile...]

pagesegmode values are:
0 = Orientation and script detection (OSD) only.
1 = Automatic page segmentation with OSD.
2 = Automatic page segmentation, but no OSD, or OCR
3 = Fully automatic page segmentation, but no OSD. (Default)
4 = Assume a single column of text of variable sizes.
5 = Assume a single uniform block of vertically aligned text.
6 = Assume a single uniform block of text.
7 = Treat the p_w_picpath as a single text line.
8 = Treat the p_w_picpath as a single word.
9 = Treat the p_w_picpath as a single word in a circle.
10 = Treat the p_w_picpath as a single character.
-l lang and/or -psm pagesegmode must occur before anyconfigfile.

Single options:
-v --version: version info
--list-langs: list available languages for tesseract engine

tesseract p_w_picpathname outputbase [-l lang] [-psm pagesegmode] [configfile...]
tesseract    圖片名  輸出文件名 -l 字庫文件 -psm pagesegmode 配置文件

2、示例:

(1)、

tesseract code.jpg code -l chi_sim -psm 7 digits
code 生成code.txt的結(jié)果文件
-l chi_sim 表示用簡(jiǎn)體中文字庫
-psm 7 表示告訴tesseract code.jpg圖片是一行文本,默認(rèn)為 3
configfile 參數(shù)值為tessdata\configs 和 tessdata\tessconfigs 目錄下的文件名
digits 內(nèi)容為 tessedit_char_whitelist 0123456789-. 表示數(shù)字

(2)、白名單

tesseract code.jpg code -l eng -psm 7 -c tessedit_char_whitelist="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

(2)、黑名單

tesseract code.jpg code -l eng -psm 7 -c tessedit_char_blacklist="abcdefghijklmnopqrstuvwxy"


【訓(xùn)練】(以訓(xùn)練arial字體為例)

1、準(zhǔn)備一張字體圖片如下。

tesseract-ocr tips

2、用 jTessBoxEditor 將圖片轉(zhuǎn)為tif文件,將tif文件命名為 eng.arial.exp0.tif。注意這里其實(shí)可以選多張圖片。

Tools -> Merge TIFF...

3、生成坐標(biāo)文件(.box)。

tesseract.exe eng.arial.exp0.tif eng.arial.exp0 batch.nochop makebox

【語法】:tesseract [lang].[fontname].exp[num].tif [lang].[fontname].exp[num] batch.nochop makebox

lang為語言名稱,fontname為字體名稱,num為序號(hào);在tesseract中,一定要注意格式。

4、在當(dāng)前目錄創(chuàng)建 font_properties 文件,內(nèi)容如下。

eng.arial.exp0.box 1 1 1 0 0

【語法】:<fontname> <italic> <bold> <fixed> <serif> <fraktur>  

fontname為字體名稱,italic為斜體,bold為黑體字,fixed為默認(rèn)字體,serif為襯線字體,fraktur德文黑字體,1和0代表有和無,精細(xì)區(qū)分時(shí)可使用。

5、字符校正。

打開jTessBoxEditor,BOX Editor -> Open,打開 eng.arial.exp0.tif,注意多頁時(shí)頁面切換。

6、執(zhí)行批處理文件(arial.bat),生成.traineddata文件。

echo Run Tesseract for Training.. 
tesseract eng.arial.exp0.tif eng.arial.exp0 nobatch box.train 
 
echo Compute the Character Set.. 
unicharset_extractor eng.arial.exp0.box 
mftraining -F font_properties -U unicharset -O arial.unicharset eng.arial.exp0.tr 


echo Clustering.. 
cntraining eng.arial.exp0.tr 

echo Rename Files.. 
rename normproto arial.normproto 
rename inttemp arial.inttemp 
rename pffmtable arial.pffmtable 
rename shapetable arial.shapetable  

echo Create Tessdata.. 
combine_tessdata arial. 

echo. & pause

7、將生成文件中的arial.traineddata 文件拷貝到相應(yīng)tessdata目錄就可以使用啦!

tesseract code.jpg code -l arial


【參考文獻(xiàn)】

1、啥都不懂也能識(shí)別驗(yàn)證碼

2、Tesseract-OCR的簡(jiǎn)單使用與訓(xùn)練

3、Adding New Fonts to Tesseract 3 OCR Engine

4、Python做簡(jiǎn)單的驗(yàn)證碼識(shí)別(ocr)


*** walker ***


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI