[英]Python OCR Module in Linux?
我想在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 。
除了Blender的答案,那只是执行Tesseract可执行文件,我想补充一点,OCR还有其他替代方案,也可以称为外部进程。
ABBYY命令行OCR实用程序: http ://ocr4linux.com/en: start
它不是免费的,所以值得考虑的是,如果Tesseract准确性不足以完成您的任务,或者您需要更复杂的布局分析,或者您需要导出PDF,Word和其他文件。
更新:这里是ABBYY和tesseract准确性的比较: http : //www.splitbrain.org/blog/2010-06/15-linux_ocr_software_comparison
免责声明:我为ABBYY工作
python tesseract
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.