【问题标题】:pytesseract not detecting numberspytesseract 没有检测到数字
【发布时间】:2021-10-23 06:12:08
【问题描述】:

我正在尝试阅读的图片正在输出“ones”。我不知道它是怎么得到的。我的代码:

left = 980
right = 1000
top = 237
bottom = 265
CroppedImage = cropimage.crop((left,top,right,bottom))
if os.path.isfile("Price.png"):
        os.remove("Price.png")
CroppedImage.save('Price.png', 'PNG')


Check_Price = pytesseract.image_to_string(Image.open('Price.png'), lang='eng')
Check_Price = Check_Price[:-2]
if len(Check_Price) == 4:
    Found_Price = True
print(Check_Price)

我已经正确安装了 pytesseract 和 PIL。这一切都适用于我拥有的另外 2 个,但它只是不会阅读此文本。

【问题讨论】:

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


    【解决方案1】:

    你需要放大图片,使用这个代码我可以得到你需要的号码。

    import pytesseract
    from PIL import Image
    pytesseract.pytesseract.tesseract_cmd = r'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
    
    def read():
        i = Image.open('./JA9JF.png')
        scale = 2.1
        i_width = i.size[1] * scale
        i_height = i.size[0] * scale
        i = i.resize((int(i_width), int(i_height)), Image.BILINEAR)
        xconfig = "-c page_separator=''"
        Check_Price = pytesseract.image_to_string(i, lang='eng', config=xconfig)
        print(Check_Price)
    
    read()
    

    所以你的代码就是这样。

    left = 980
    right = 1000
    top = 237
    bottom = 265
    CroppedImage = cropimage.crop((left,top,right,bottom))
    if os.path.isfile("Price.png"):
            os.remove("Price.png")
    CroppedImage.save('Price.png', 'PNG')
    
    i = Image.open('Price.png')
    scale = 2.1
    i_width = i.size[1] * scale
    i_height = i.size[0] * scale
    i = i.resize((int(i_width), int(i_height)), Image.BILINEAR)
    
    xconfig = "-c page_separator=''"
    Check_Price = pytesseract.image_to_string(i, lang='eng', config=xconfig)
    Check_Price = Check_Price[:-2]
    if len(Check_Price) == 4:
        Found_Price = True
    print(Check_Price)
    

    我已经添加了xconfig = "-c page_separator=''",因为对我来说 pytesseract add \n\x0c 出于某种原因。我也不知道这是否适用于其他数字,如果不能,我将不得不使用 cv2 修复它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-12
      • 2021-12-12
      • 2021-03-07
      • 2021-07-12
      • 1970-01-01
      • 2021-08-06
      相关资源
      最近更新 更多