When I use pytesser (the image processing lib with tesseract-ocr for python) and run:
当我使用pytesser (python中带有tesserac -ocr的图像处理库)并运行时:
image= Image.open(ImagePath)
text = image_to_string(image)
print text
as a result I get the text
, as well as this line from tesseract:
结果,我得到了文本,以及来自tesseract的这一行:
Tesseract Open Source OCR Engine v3.02 with Leptonica
I think this line runs when the image_to_string
function is run.
我认为这一行在运行image_to_string函数时运行。
This really clogs up the output printed in the console. And is really annoying. Does anyone know how to get rid of it? Maybe a line in python or something?
这确实会阻塞控制台中打印的输出。,真的很烦人。有人知道怎么处理吗?可能是python里的一条线还是什么?
4 个解决方案
#1
1
What you do is open pytesser.py
in the main pytesser
folder and change this function:
你要做的是打开pytesser。py在pytesser主文件夹中并更改此函数:
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()
to
来
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()
and also add import os
to the top of the file.
并将导入操作系统添加到文件的顶部。
#2
1
Frist create a config file
创建一个配置文件。
cat <<CNF >>/usr/share/tessdata/tessconfigs/nobanner
debug_file /dev/null
CNF
Note that your tessconfigs could be somewhere else, likes /usr/local/share/tessdata/tessconfigs.
注意,您的tessconfigs可能在其他地方,比如/usr/local/share/tessdata/tessconfigs。
Then use 'nobanner' on the command line
然后在命令行上使用“nobanner”。
tesseract infile.png outprefix -l eng nobanner
#3
1
only the code below got success:
只有下面的代码成功了:
tesseract infile.png outprefix 1>/dev/null 2>&1
#4
0
You can try to redirect it to a log file by setting the debug_file
parameter.
可以通过设置debug_file参数将其重定向到日志文件。
#1
1
What you do is open pytesser.py
in the main pytesser
folder and change this function:
你要做的是打开pytesser。py在pytesser主文件夹中并更改此函数:
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()
to
来
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()
and also add import os
to the top of the file.
并将导入操作系统添加到文件的顶部。
#2
1
Frist create a config file
创建一个配置文件。
cat <<CNF >>/usr/share/tessdata/tessconfigs/nobanner
debug_file /dev/null
CNF
Note that your tessconfigs could be somewhere else, likes /usr/local/share/tessdata/tessconfigs.
注意,您的tessconfigs可能在其他地方,比如/usr/local/share/tessdata/tessconfigs。
Then use 'nobanner' on the command line
然后在命令行上使用“nobanner”。
tesseract infile.png outprefix -l eng nobanner
#3
1
only the code below got success:
只有下面的代码成功了:
tesseract infile.png outprefix 1>/dev/null 2>&1
#4
0
You can try to redirect it to a log file by setting the debug_file
parameter.
可以通过设置debug_file参数将其重定向到日志文件。