2014-12-20 91 views
1

TL; DR看來tesseract無法識別由單個數字組成的圖像。有沒有解決方法/原因呢?有沒有辦法使用tesseract單個數字的數字?

我正在使用(僅數字版本)tesseract來自動向系統輸入發票。然而,我注意到,正方體似乎是無法識別的個位數,如下列:

作物後的原始掃描:

enter image description here

我做了一些圖像增強後:

enter image description here

它工作正常,如果它至少有兩個數字:

enter image description here enter image description here

我一對夫婦的其他數據進行測試:

不工作: enter image description hereenter image description hereenter image description here

工作: enter image description hereenter image description hereenter image description here

如果有幫助,爲了我的目的,tesseract的所有輸入都按照上面的方式裁剪和旋轉。我使用pyocr作爲我的項目和tesseract之間的橋樑。

回答

0

這裏是你如何配置pyocr識別單個數字:

from PIL import Image 
import sys 
import pyocr 
import pyocr.builders 

tools = pyocr.get_available_tools() 
if len(tools) == 0: 
    print("No OCR tool found") 
    sys.exit(1) 
tool = tools[0] 

im = Image.open('digit.png') 
builder = pyocr.builders.DigitBuilder() 

# Set Page Segmentation mode to Single Char : 
builder.tesseract_layout = 10 # If tool = tesseract 
builder.tesseract_flags = ['-psm', '10'] # If tool = libtesseract 

result = tool.image_to_string(im, lang="eng", builder=builder) 
相關問題