Linux中的Python OCR模块?

2024-06-18 02:25:55 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我试着把代码改成了用葡萄酒,它真的很管用,但是太慢了,真的不是个好主意。

有没有Linux的替代品可以像它一样容易使用?


Tags: 模块代码com可执行文件替代品linuxgooglecode
3条回答

Python镶嵌

http://code.google.com/p/python-tesseract

import cv2.cv as cv
import tesseract

api = tesseract.TessBaseAPI()
api.Init(".","eng",tesseract.OEM_DEFAULT)
api.SetPageSegMode(tesseract.PSM_AUTO)

image=cv.LoadImage("eurotext.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE)
tesseract.SetCvImage(image,api)
text=api.GetUTF8Text()
conf=api.MeanTextConf()

除了Blender的答案,即只执行Tesseract可执行文件外,我还想补充一点,OCR还有其他替代方案,也可以称为外部进程。

ABBYY命令行OCR实用程序:http://ocr4linux.com/en:start

它不是免费的,因此只有在以下情况下才值得考虑:细分精度不足以完成任务,或者需要更复杂的布局分析,或者需要导出PDF、Word和其他文件。

更新:这里是ABBYY和tesseract精度的比较:http://www.splitbrain.org/blog/2010-06/15-linux_ocr_software_comparison

免责声明:我为ABBYY工作

您只需在函数中包装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

相关问题 更多 >