【问题标题】:How to properly recognize the number in this kind of images?如何正确识别此类图像中的数字?
【发布时间】:2021-06-25 14:03:25
【问题描述】:

我正在尝试制作一个可以识别图片中数字的脚本,更准确地说,图片与这个非常相似:

这从501,但我在使用pytesseract 读取其中的数字时遇到了一些问题。这是我用来阅读它的代码:

im = Image.open(filename)
text = image_to_string(im)

我得到的所有结果都是这样的:

我可以做些什么来提高读数?

【问题讨论】:

    标签: python python-3.x ocr tesseract python-tesseract


    【解决方案1】:

    Improving the quality of the output 是您使用 Tesseract 时的“圣经”。在二值化之前,你可以先尝试grayscale你的图片:

    from PIL import Image
    import pytesseract
    
    im = Image.open('G9hvi.png').convert('L')
    text = pytesseract.image_to_string(im)
    print(text.replace('\f', ''))
    # 50
    

    轰隆隆! – 无需任何进一步的预处理,您已经得到正确的结果。

    ----------------------------------------
    System information
    ----------------------------------------
    Platform:      Windows-10-10.0.19041-SP0
    Python:        3.9.1
    PyCharm:       2021.1.2
    Pillow:        8.2.0
    pytesseract:   5.0.0-alpha.20201127
    ----------------------------------------
    

    【讨论】:

    • 是的,有些数字可以正常工作,但其他数字他看不懂。我注意到的一件事是,DPI 远不接近 300,这是建议与 tesseract 一起使用的最低值,所以我假设我需要调整图像的大小以获得良好的 dpi,但我需要调整多少?
    • 请张贴图片,这不起作用。 |阅读链接的文章!正确的图像预处理是最重要的。 pytesseract 正确识别此类图像中的数字没有问题。但最有可能的是,其他图像具有(可能只是略微)不同的外观,但这足以满足需要比呈现的灰度更高级的预处理。
    猜你喜欢
    • 1970-01-01
    • 2018-07-08
    • 2010-12-21
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多