【问题标题】:Pytesseract: Cannot read digits on a relatively good quality imagePytesseract:无法读取质量相对较好的图像上的数字
【发布时间】:2021-03-16 13:35:51
【问题描述】:

我有一张如下图:

使用 tesseract 命令:

pytesseract.image_to_string(box_img_6, config="--lang= 'eng' --psm 6 --oem 3")

我得到输出:'nu'

我认为 tesseract 应该在这张图片上表现更好,至少可以读取一些数字。

你能帮我提高 Tesseract 的性能吗?

谢谢。

【问题讨论】:

    标签: python opencv tesseract python-tesseract


    【解决方案1】:

    试试这个代码

    import pytesseract
    from PIL import Image
    pytesseract.pytesseract.tesseract_cmd = (r"C:\Tesseract-OCR\tesseract.exe")
    text = pytesseract.image_to_string(Image.open(r"a.jpg"), lang='eng',
                            config='--psm 10 --oem 3 -c tessedit_char_whitelist=0123456789')
    
    print(text)
    

    输出

    **3008**
    

    【讨论】:

    • 您好,感谢您的回答。我可以学习你的 tesseract 版本吗,因为我没有得到相同的结果。
    • 是的,放弃你的邮件。我将向您发送 tesseract zip 二进制文件。稍后您可以通过复制提取文件的路径来添加代码路径
    【解决方案2】:

    您应该阅读Improving the quality of the output

    但是对于输入图像,你不需要应用任何预处理或设置任何配置参数,结果:

    txt = pytesseract.image_to_string(gray_image)
    

    将是:

    3008
    

    在当前最新版本的 pytesseract (0.3.7) 中

    代码:


    import cv2
    import pytesseract
    
    # Load the image
    img = cv2.imread("wwckp.jpg")
    
    # Convert to the gray-scale
    gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    
    # OCR
    txt = pytesseract.image_to_string(gry)
    print(txt)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-01
      • 2020-10-28
      • 2023-02-07
      • 1970-01-01
      • 1970-01-01
      • 2021-04-14
      • 2020-10-23
      • 1970-01-01
      相关资源
      最近更新 更多