Tesseract-OCR引擎 入門

來源:互聯網
上載者:User

OCR(Optical Character Recognition):光學字元辨識,是指對圖片檔案中的文字進行分析識別,擷取的過程。

Tesseract:開源的OCR識別引擎,初期Tesseract引擎由HP實驗室研發,後來貢獻給了開源軟體業,後經由Google進行改進,消除bug,最佳化,重新發布。目前的版本為3.01.

項目地址為:http://code.google.com/p/tesseract-ocr

 

Windows 命令列使用Tesseract-OCR引擎識別驗證碼:

1、下載安裝Tesseract-OCR引擎(3.0版本+才支援中文識別)

tesseract-ocr-setup-3.01-1.exe

下載完後進行安裝,預設情況下安裝程式會給你配置系統內容變數,以指向安裝目錄(之後可以通過DOS介面在任意目錄運行tesseract)。安裝完成後目錄如下:

附錄:

 tessdata 目錄存放的是語言字型檔檔案,和在命令列介面中可能用到的參數所對應的檔案.  這個安裝程式預設包含了英文字型檔。

如果想能識別中文,可以到http://code.google.com/p/tesseract-ocr/downloads/list下載對應的語言的字型檔檔案. 

簡體中文字型檔檔案為:http://tesseract-ocr.googlecode.com/files/chi_sim.traineddata.gz 下載完成後解壓,然後將該檔案剪下到tessdata目錄下去就可以了。

 

2、使用Tessract-OCR引擎識別驗證碼

開啟DOS介面,輸入tesseract:

如果出現如上輸出,表示安裝正常。

我準備了一張驗證碼code.jpg放在D盤根目錄下,:

結果為:

 

附錄:

Usage:tesseract 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.

 

tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...]

tesseract    圖片名  輸出檔案名 -l 字型檔檔案 -psm pagesegmode 設定檔

例如:

tesseract code.jpg result  -l chi_sim -psm 7 nobatch

-l chi_sim 表示用簡體中文字型檔(需要下載中文字型檔檔案,解壓後,存放到tessdata目錄下去,字型檔副檔名為  .raineddata 簡體中文字型檔檔案名稱為:  chi_sim.traineddata)

-psd 7 表示告訴tesseract code.jpg圖片是一行文本  這個參數可以減少識別錯誤率.  預設為 3

configfile 參數值為tessdata\configs 和  tessdata\tessconfigs 目錄下的檔案名稱

ps:紅色的-psm的原文章裡為-psd

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.