如何去除“Tesseract 开源 OCR 引擎 v3.02 和 Leptonica”消息
当我使用pytesser这个图像处理库(它是用来和tesseract-ocr一起工作的Python库)并运行:
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里加一行代码什么的?
4 个回答
0
你可以尝试通过设置 debug_file
这个参数,把错误信息 重定向到一个日志文件。
1
下面的代码是唯一成功的:
tesseract infile.png outprefix 1>/dev/null 2>&1
1
首先,创建一个配置文件。
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
1
你需要做的是打开主文件夹中的 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
这一行。