从子进程调用exe - xyv exe已停止工作

时间:2017-11-03 13:39:19

标签: python tesseract python-tesseract

我定期从Tesseract OCR收到以下错误,尽管我也从其他可执行文件中收到了错误。

enter image description here

是否有解决方案或方法可以更好地构建我的popen来电以避免此问题?

我想象一个可能会遇到这类第三方问题的subprocess.try_execute

def run_tesseract(img_path,out_file='C:/temp/tesser_output'):

    image = Image.open(img_path)

    if len(image.split()) == 4:
        # In case we have 4 channels, lets discard the Alpha.
        # Kind of a hack, should fix in the future some time.
        r, g, b, a = image.split()
        image = Image.merge("RGB", (r, g, b))

    image.save(img_path)

    command = '"C:/Program Files (x86)/Tesseract-OCR/tesseract.exe" '+img_path+' '+ out_file +' -l eng'
    # print command
    res = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
    tmp = res.stdout.read()

    try:
        f = open(out_file + '.txt', 'rb')
        out = f.read().decode('utf-8').strip()
    except:
        traceback.print_exc()
    finally:
        f.close()

    return out

0 个答案:

没有答案