圖片文字OCR識別-tesseract-ocr


   幫助文件:https://github.com/tesseract-ocr/tesseract/blob/master/doc/tesseract.1.asc

  下載地址:https://github.com/tesseract-ocr/tesseract/wiki

  如何使用提供的工具來訓練Tesseract 4.00:https://github.com/tesseract-ocr/tesseract/wiki/TrainingTesseract-4.00

  1、介紹

    圖片文字的OCR識別有一款開源原件tesseract-ocr,最初是在linux上,當然現在也有windows版本,現在發展到4.0版本。

  2、下載tesseract-ocr

    下載地址:https://github.com/tesseract-ocr/tesseract/wiki

    里面有linux版本、macOS版本還有windows版本

    下面下載windows版本,如下圖:

    

    點擊上面的鏈接,進入

    

 

    下載完成

    

  3、安裝,設置環境變量

    雙擊上的exe,進行安裝

    

    

    

    

    

    

    

    安裝完后打開軟件坐在目錄,這里我選擇的是默認目錄C:\Program Files (x86)\Tesseract-OCR

    安裝目錄C:\Program Files (x86)\Tesseract-OCR,安裝完成后,設置環境變量

    

    在系統變量下面點擊新建,按照如圖建一個變量如圖

    變量名TESSDATA_PREFIX,變量值:C:\Program Files (x86)\Tesseract-OCR\tessdata

    

  4、應用

    經過上面的調整tesseract命令可以在任意目錄調用了,下面是tessract應用實例

    4.1、識別中文圖片

    

    

    識別結果:

    

 

 

    命令:tesseract 中文.png log -l chi_sim

    把圖片文件上的中文字符識別出來,寫到log文本文件里面

 

 

    4.2、識別英文圖片

    tesseract.exe 英文.png log -l eng

     

    

   

    識別結果:

    

 

    4.3、識別中英文混合

    tesseract.exe 中文-英文-混合.png log -l chi_sim+eng

 

     識別結果效果,中文部分不好

    

     

    如果用 tesseract 中文-英文-混合.png log -l chi_sim

    識別結果:顯示中文識別比較好,但是因為有出息識別成中文的情況

    

 

    

    4.4、識別簡單數字

    

    

    tesseract num.png log -l chi_sim
    tesseract num.png log -l eng

    都可以正常識別

    如下面復雜的識別碼就識別不了

    

    

    

    總結:在識別只包含英文和數字的圖片可以用簡單的命令:

        tesseract num.png log

        如果包含中文的必須指定中文庫:chi_sim

        tesseract num1.png log -l chi_sim

   

   附錄:

    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)

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

    configfile 參數值為tessdata\configs 和  tessdata\tessconfigs 目錄下的文件名

 


免責聲明!

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



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