【问题标题】:Improving the output of tesseract while detecting phone numbers在检测电话号码时改进 tesseract 的输出
【发布时间】:2020-06-13 20:58:21
【问题描述】:

我遇到了在图像中读取电话号码的问题。我尝试使用 tesseract 在图像中检测它们,但有时它会给我一个错误的答案。例如,数字是 8 995 005-81-86,但 tesseract 给我 8 995 0005-81-86 作为输出。我该如何解决?也许二值化?


代码很基础

import pytesseract as pt
from PIL import Image

img = Image.open('1.png')
number = pt.image_to_string(img)

print(number)

https://i.stack.imgur.com/kvhAq.png

【问题讨论】:

    标签: ocr tesseract python-tesseract


    【解决方案1】:

    您应该传递黑白文本以获得最佳效果:

    import cv2
    from PIL import Image
    
    img = cv2.imread('kvhAq.png')
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    ret, thresh = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY)
    im = Image.fromarray(thresh.astype("uint8"))
    print(pytesseract.image_to_string(im))
    

    【讨论】:

    • 谢谢,但无论如何它有时会给出错误的答案
    • 这取决于您传递给它的图像类型。他们总是像你提供的例子一样吗?
    • 另外,尝试将不同的页面分割模式传递给pytesseract,看看是否有帮助:custom_oem_psm_config = r'--psm 6' pytesseract.image_to_string(image, config=custom_oem_psm_config)
    • 另一个技巧是在图像周围放置一个更大的白色边框。我注意到这可以改善检测。此外,您可以将图像放大。
    • 照片都一样
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    • 2013-07-11
    • 2013-12-09
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 2012-05-03
    相关资源
    最近更新 更多