代码之家  ›  专栏  ›  技术社区  ›  Atinesh

Tesseract OCR在TIFF文件上失败

  •  0
  • Atinesh  · 技术社区  · 6 年前

    我有多页 .tif 文件,我试图从中提取文本使用Tesseract OCR,但我得到这个错误

    代码

    from PIL import Image
    import pytesseract
    
    img = Image.open('Group 1/1_CHE_MDC_1.tif')
    text = pytesseract.image_to_string(img.seek(0))  # OCR on 1st Page
    text = ' '.join(text.split())
    print(text)
    

    错误

    enter image description here

    知道为什么吗

    2 回复  |  直到 6 年前
        1
  •  2
  •   Blender    6 年前

    Image.seek 没有返回值,因此您实际上正在运行:

    pytesseract.image_to_string(None)
    

    相反,请执行以下操作:

    img.seek(0)
    text = pytesseract.image_to_string(img)
    
        2
  •  1
  •   Jitesh Vacheta    6 年前

    我有一个同样的问题,我尝试了下面的代码,它为我工作:-

    导入全局
    导入操作系统

    “设置Tesseract OCR.exe文件路径” )

    b = ''
    for i in glob.glob('Fullpath of your image directory/*.tif'):  <-- you can give *.jpg extension in case of jpg image
        if  glob.glob('*.tif'):
            b = b +  (pytesseract.image_to_string(i))
    print(b)
    

    学习愉快!