【问题标题】:Incorrect thresholding before string recognition字符串识别前阈值不正确
【发布时间】:2019-09-25 16:26:36
【问题描述】:

我正在尝试使用 pytesseract 识别一些文本,但在此之前我必须将我拥有的图片转换为二进制图片。 请注意,我首先调整了图片的大小,以便 pytesseract 更易于阅读。

请看下面的原始图片,调整大小的图片,我的代码和我得到的结果,这样你就可以理解我的问题了..

Original picture

image = cv2.imread('original.png',0)
image = cv2.resize(image,None,fx=2,fy=2,interpolation=cv2.INTER_CUBIC)
cv2.imwrite("resized.png", image)

thresh = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
result = 255 - thresh
cv2.imwrite("after_threshold.png", result)

Resized picture

Picture after threshold

感谢您的帮助:)

【问题讨论】:

    标签: python opencv tesseract python-tesseract threshold


    【解决方案1】:

    如果你删除调整大小,它似乎工作

    Pytesseract 的输出

    32 Force
    
    120 Initiative
    Prospection
    
    25 agilité
    
    53 Vitalité
    
    5 Dommages
    
    1 Résistance Neutre
    1 Portée
    
    7% Résistance Feu
    
    import cv2
    import pytesseract
    
    pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
    
    image = cv2.imread('1.png', 0)
    thresh = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
    result = 255 - thresh 
    
    data = pytesseract.image_to_string(result, lang='eng',config='--psm 6')
    print(data)
    
    cv2.imshow('thresh', thresh)
    cv2.imshow('result', result)
    cv2.waitKey()
    

    【讨论】:

      猜你喜欢
      • 2013-01-05
      • 1970-01-01
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-13
      相关资源
      最近更新 更多