【问题标题】:How to remove "Tesseract Open Source OCR Engine v3.02 with Leptonica" message如何删除“Tesseract Open Source OCR Engine v3.02 with Leptonica”消息
【发布时间】:2014-07-24 17:51:52
【问题描述】:

当我使用 pytesser(用于 python 的带有 tesseract-ocr 的图像处理库)并运行时:

image= Image.open(ImagePath)
text = image_to_string(image)
print text

因此,我得到了 text,以及来自 tesseract 的这一行:

Tesseract Open Source OCR Engine v3.02 with Leptonica

我认为当image_to_string 函数运行时这条线会运行。

这确实阻塞了控制台中打印的输出。而且真的很烦人。有谁知道如何摆脱它?也许是 python 中的一行之类的?

【问题讨论】:

标签: python image-processing ocr tesseract python-tesseract


【解决方案1】:

您所做的是在主pytesser 文件夹中打开pytesser.py 并更改此功能:

def call_tesseract(input_filename, output_filename):
    """Calls external tesseract.exe on input file (restrictions on types),
    outputting output_filename+'txt'"""
    args = [tesseract_exe_name, input_filename, output_filename]
    proc = subprocess.Popen(args)
    retcode = proc.wait()
    if retcode!=0:
        errors.check_for_errors()

def call_tesseract(input_filename, output_filename):
    """Calls external tesseract.exe on input file (restrictions on types),
    outputting output_filename+'txt'"""
    devnull = open(os.devnull, 'w')
    args = [tesseract_exe_name, input_filename, output_filename]
    proc = subprocess.Popen(args, stderr=devnull)
    retcode = proc.wait()
    if retcode!=0:
        errors.check_for_errors()

并将import os 添加到文件顶部。

【讨论】:

  • 检查文件,没有名为 call__tesseract 的函数。还有其他建议吗?
【解决方案2】:

首先创建一个配置文件

cat <<CNF >>/usr/share/tessdata/tessconfigs/nobanner
debug_file /dev/null
CNF

请注意,您的 tessconfigs 可能位于其他位置,例如 /usr/local/share/tessdata/tessconfigs。

然后在命令行中使用'nobanner'

tesseract infile.png outprefix -l eng nobanner

【讨论】:

    【解决方案3】:

    只有下面的代码成功了:

    tesseract infile.png outprefix 1>/dev/null 2>&1
    

    【讨论】:

      【解决方案4】:

      您可以通过设置debug_file参数来尝试redirect it to a log file

      【讨论】:

      • 我该怎么做...?
      • api.Init之后致电api.SetVariable("debug_file", "tesseract.log")
      猜你喜欢
      • 1970-01-01
      • 2018-11-25
      • 2018-04-11
      • 2012-10-09
      • 2017-11-03
      • 1970-01-01
      • 2023-03-20
      • 2011-12-30
      • 2017-09-22
      相关资源
      最近更新 更多