Tesseract Ocr引擎


Tesseract Ocr引擎

1、Tesseract介紹

tesseract 是一個google支持的開源ocr項目,其項目地址:https://github.com/tesseract-ocr/tesseract,目前最新的源碼可以在這里下載。

實際使用tesseract ocr也有兩種方式:1- 動態庫方式 libtesseract  2  - 執行程序方式 tesseract.exe

由於本人也是python菜鳥一個,所以方式1暫時不會,只好采取方式2。

 

2、Tesseract安裝包下載

Tesseract的release版本下載地址:https://github.com/tesseract-ocr/tesseract/wiki/Downloads,這里需要注意這一段話:

Currently, there is no official Windows installer for newer versions.

意思就是官方不提供最新版windows平台安裝包,只有相對略老的3.02.02版本,其下載地址:https://sourceforge.net/projects/tesseract-ocr-alt/files/

最新版3.03和3.05版本,都是三方維護和管理的安裝包,有好幾個發行機構,分別是:

3rd party Windows exe's/installer

 

總結一下:

1、官方發布的3.02版本下載地址:http://downloads.sourceforge.net/project/tesseract-ocr-alt/tesseract-ocr-setup-3.02.02.exe?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Ftesseract-ocr-alt%2Ffiles%2F&ts=1464880498&use_mirror=jaist

2、德國曼海姆大學發行的3.05版本下載地址,http://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-setup-3.05.00dev.exe

3、Simon Eigeldinger (@DomasoFan) 維護的另一個版本:http://3.onj.me/tesseract/,值得稱道的是,這個網址里還有一個比較詳細的說明。

以上版本如果在下載時發現無法下載,可以首先試試迅雷,其次,可能就需要FQ了。

本人使用的是官方發布的3.02版本,也就是鏈接1.

 

3、Tesseract ocr使用說明

安裝之后,默認目錄C:\Program Files (x86)\Tesseract-OCR,你需要把這個路徑放到你操作系統的path搜索路徑中,否則后面使用起來會不方便。

在安裝目錄C:\Program Files (x86)\Tesseract-OCR下可以看到 tesseract.exe這個命令行執行程序。

tesseract語法如下:

例如:tesseract 1.png output-l eng -psm 7 ,表示采取單行文本方式,使用英語字庫識別1.png這個圖片文件,識別結果輸出到當前目錄output.txt文件中。

復制代碼
 1 D:\python\lnypcg\test>tesseract
 2 Usage:tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...]
 3 
 4 pagesegmode values are:
 5 0 = Orientation and script detection (OSD) only.
 6 1 = Automatic page segmentation with OSD.
 7 2 = Automatic page segmentation, but no OSD, or OCR
 8 3 = Fully automatic page segmentation, but no OSD. (Default)
 9 4 = Assume a single column of text of variable sizes.
10 5 = Assume a single uniform block of vertically aligned text.
11 6 = Assume a single uniform block of text.
12 7 = Treat the image as a single text line. #-psm 7 表示用單行文本識別
13 8 = Treat the image as a single word.
14 9 = Treat the image as a single word in a circle.
15 10 = Treat the image as a single character.
16 -l lang and/or -psm pagesegmode must occur before anyconfigfile. #-l eng 代表使用英語識別
17 
18 Single options:
19   -v --version: version info
20   --list-langs: list available languages for tesseract engine
復制代碼

 

 

4、Tesseract ocr使用實例

 

現在有一個經過灰度處理之后的驗證碼文件,在命令行中調用tesseract.exe實現默認,並把識別出來的文本輸出到output.txt文本文件中。

(如何灰度處理,在python里可以使用PIL庫,先挖個坑,下次寫。)

復制代碼
 1 D:\python\lnypcg\test>dir
 2  驅動器 D 中的卷沒有標簽。
 3  卷的序列號是 36D9-CDC7
 4 
 5  D:\python\lnypcg\test 的目錄
 6 
 7 2016-06-02  23:28    <DIR>          .
 8 2016-06-02  23:28    <DIR>          ..
 9 2016-06-02  22:02               462 1.png
10                1 個文件            462 字節
11                2 個目錄 25,733,357,568 可用字節
12 
13 D:\python\lnypcg\test>tesseract 1.png output -l eng
14 Tesseract Open Source OCR Engine v3.02 with Leptonica
15 
16 D:\python\lnypcg\test>type output.txt
17 7572
18 
19 
20 D:\python\lnypcg\test>
復制代碼

 

總結,tesseract是一個挺不錯的OCR引擎,目前的問題是最新的中文資料相對較少,過時、不准確的信息偏多,把這幾天的琢磨的結果分享給大家,希望對大家有所幫助。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM