【发布时间】:2016-03-18 20:08:37
【问题描述】:
我使用 pytesseract 获得了非常好的结果,但它无法保留双空格,它们对我来说非常重要。 而且,所以我决定检索 hocr 输出而不是纯文本。但是;似乎没有任何方法可以使用 pytessearct 指定配置文件。
那么,是否可以使用 pytesseract 指定配置文件,或者是否有一些默认配置文件可以更改以获取 hocr 输出?
#run method from pytessearct.py
def run_tesseract(input_filename, output_filename_base, lang=None, boxes=False, config=None):
'''
runs the command:
`tesseract_cmd` `input_filename` `output_filename_base`
returns the exit status of tesseract, as well as tesseract's stderr output
'''
command = [tesseract_cmd, input_filename, output_filename_base]
if lang is not None:
command += ['-l', lang]
if boxes:
command += ['batch.nochop', 'makebox']
if config:
command += shlex.split(config)
#command+=['C:\\Program Files (x86)\\Tesseract-OCR\\tessdata\\configs\\hocr']
#print "command:",command
proc = subprocess.Popen(command,
stderr=subprocess.PIPE)
return (proc.wait(), proc.stderr.read())
【问题讨论】:
-
您只需要新选项“preserve_interword_spaces=1”,因此您的最终配置如下所示:custom_config = '--oem 1 --psm 11 -c preserve_interword_spaces=1'
标签: tesseract python-tesseract hocr