简体   繁体   English

Linux中的Python OCR模块?

[英]Python OCR Module in Linux?

I want to find a easy-to-use OCR python module in linux, I have found pytesser http://code.google.com/p/pytesser/ , but it contains a .exe executable file. 我想在linux中找到一个易于使用的OCR python模块,我找到了pytesser http://code.google.com/p/pytesser/ ,但它包含一个.exe可执行文件。

I tried changed the code to use wine, and it really works, but it's too slow and really not a good idea. 我尝试改变代码使用wine,它确实有效,但它太慢了,真的不是一个好主意。

Is there any Linux alternatives that as easy-to-use as it? 是否有任何易用的Linux替代品?

You can just wrap tesseract in a function: 你可以在一个函数中包装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

If you want document segmentation and more advanced features, try out OCRopus . 如果您想要文档分段和更高级的功能,请试用OCRopus

In addition to Blender's answer, that just executs Tesseract executable, I would like to add that there exist other alternatives for OCR that can also be called as external process. 除了Blender的答案,那只是执行Tesseract可执行文件,我想补充一点,OCR还有其他替代方案,也可以称为外部进程。

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

It is not free, so worth to consider only if Tesseract accuracy is not good enough for your task, or you need more sophisticated layout analisys or you need to export PDF, Word and other files. 它不是免费的,所以值得考虑的是,如果Tesseract准确性不足以完成您的任务,或者您需要更复杂的布局分析,或者您需要导出PDF,Word和其他文件。

Update: here's comparison of ABBYY and tesseract accuracy: http://www.splitbrain.org/blog/2010-06/15-linux_ocr_software_comparison 更新:这里是ABBYY和tesseract准确性的比较: http//www.splitbrain.org/blog/2010-06/15-linux_ocr_software_comparison

Disclaimer: I work for ABBYY 免责声明:我为ABBYY工作

python tesseract python tesseract

http://code.google.com/p/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()

You should try the excellent scikits.learn libraries for machine learning. 您应该尝试使用优秀的scikits.learn库进行机器学习。 You can find two codes that are ready to run here and here . 你可以找到两个准备在这里这里运行的代码。

You have a bunch of options here. 你有很多选择。

One way, as others pointed out is to use tesseract. 正如其他人所指出的那样,一种方法是使用tesseract。 Looks like there are a bunch of wrappers by now, so best way is to do a quick pypi search for it. 看起来现在有一堆包装器,所以最好的方法是快速搜索它。 The most used ones these days are: 这些天最常用的是:

Another useful site for finding similar engines is alternative.to . 另一个寻找类似引擎的有用网站是另类 A few linux based systems according to them are: 根据它们的一些基于Linux的系统是:

  • ABBYY ABBYY
  • Tesseract 正方体
  • CuneiForm 楔形的
  • Ocropus Ocropus
  • GOCR GOCR

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM