tesseract-ocr tips
【基本用法】
1、tesseract?基本語法:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | Usage:tesseract.exe?imagename?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?image?as?a?single?text?line. 8?=?Treat?the?image?as?a?single?word. 9?=?Treat?the?image?as?a?single?word?in?a?circle. 10?=?Treat?the?image?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?imagename?outputbase?[-l?lang]?[-psm?pagesegmode]?[configfile...] tesseract????圖片名??輸出文件名?-l?字庫文件?-psm?pagesegmode?配置文件 |
2、示例:
(1)、
| 1 2 3 4 5 6 | tesseract?code.jpg?code?-l?chi_sim?-psm?7?digits code?生成code.txt的結果文件 -l?chi_sim?表示用簡體中文字庫 -psm?7?表示告訴tesseract?code.jpg圖片是一行文本,默認為?3 configfile?參數值為tessdata\configs?和?tessdata\tessconfigs?目錄下的文件名 digits?內容為?tessedit_char_whitelist?0123456789-.?表示數字 |
(2)、白名單
| 1 | tesseract?code.jpg?code?-l?eng?-psm?7?-c?tessedit_char_whitelist="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" |
(2)、黑名單
| 1 | tesseract?code.jpg?code?-l?eng?-psm?7?-c?tessedit_char_blacklist="abcdefghijklmnopqrstuvwxy" |
【訓練】(以訓練arial字體為例)
1、準備一張字體圖片如下。
2、用?jTessBoxEditor?將圖片轉為tif文件,將tif文件命名為?eng.arial.exp0.tif。注意這里其實可以選多張圖片。
| 1 | Tools?->?Merge?TIFF... |
3、生成坐標文件(.box)。
| 1 | 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為序號;在tesseract中,一定要注意格式。
4、在當前目錄創建?font_properties 文件,內容如下。
| 1 | eng.arial.exp0.box?1?1?1?0?0 |
【語法】:<fontname> <italic> <bold> <fixed> <serif> <fraktur>??
fontname為字體名稱,italic為斜體,bold為黑體字,fixed為默認字體,serif為襯線字體,fraktur德文黑字體,1和0代表有和無,精細區分時可使用。
5、字符校正。
打開jTessBoxEditor,BOX Editor -> Open,打開?eng.arial.exp0.tif,注意多頁時頁面切換。
6、執行批處理文件(arial.bat),生成.traineddata文件。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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 文件拷貝到相應tessdata目錄就可以使用啦!
| 1 | tesseract?code.jpg?code?-l?arial |
【參考文獻】
1、啥都不懂也能識別驗證碼
2、Tesseract-OCR的簡單使用與訓練
3、Adding New Fonts to Tesseract 3 OCR Engine
4、Python做簡單的驗證碼識別(ocr)
***?walker?***
本文轉自walker snapshot博客51CTO博客,原文鏈接http://blog.51cto.com/walkerqt/1844753如需轉載請自行聯系原作者
RQSLT
總結
以上是生活随笔為你收集整理的tesseract-ocr tips的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: kvm安装完全版 rhel6
- 下一篇: 一步一步SharePoint 2007之