小编Anu*_*rag的帖子

如何使用python-tesseract获取Hocr输出

使用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())
Run Code Online (Sandbox Code Playgroud)

tesseract hocr python-tesseract

3
推荐指数
3
解决办法
7708
查看次数

标签 统计

hocr ×1

python-tesseract ×1

tesseract ×1