gpt4 book ai didi

Linux中的Python OCR模块?

转载 作者:IT老高 更新时间:2023-10-28 20:45:44 25 4
gpt4 key购买 nike

我想在linux中找一个好用的OCR python模块,我找到了pytesser http://code.google.com/p/pytesser/ , 但它包含一个 .exe 可执行文件。

我尝试将代码更改为使用wine,它确实有效,但它太慢了,真的不是一个好主意。

有没有像它一样易于使用的 Linux 替代品?

最佳答案

您可以将 tesseract 包装在一个函数中:

import os
import tempfile
import subprocess

def ocr(path):
temp = tempfile.NamedTemporaryFile(delete=False)

process = subprocess.Popen(['tesseract', path, temp.name], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
process.communicate()

with open(temp.name + '.txt', 'r') as handle:
contents = handle.read()

os.remove(temp.name + '.txt')
os.remove(temp.name)

return contents

如果您想要文档分割和更高级的功能,请尝试 OCRopus .

关于Linux中的Python OCR模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5799946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com