Tesseract和Tesseract有什么区别?

问题描述 投票:2回答:3

我在Windows 10中使用Python 3.6并且已经安装了Pytesseract但我在code Tesserocr中发现了我无法安装的方式。有什么不同?

我有Visual Studio Community 2017和Anaconda。

错误如下:

creating build\temp.win32-3.6\Release
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\omen\appdata\local\programs\python\python36-32\include -Ic:\users\omen\appdata\local\programs\python\python36-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-ID:\Windows Kits\10\include\10.0.17763.0\ucrt" "-ID:\Windows Kits\10\include\10.0.17763.0\shared" "-ID:\Windows Kits\10\include\10.0.17763.0\um" "-ID:\Windows Kits\10\include\10.0.17763.0\winrt" "-ID:\Windows Kits\10\include\10.0.17763.0\cppwinrt" /EHsc /Tptesserocr.cpp /Fobuild\temp.win32-3.6\Release\tesserocr.obj -std=c++11 -DUSE_STD_NAMESPACE
    clÿ: Ligne de commande warning D9002ÿ: option '-std=c++11' inconnue ignor‚e
    tesserocr.cpp
    tesserocr.cpp(633): fatal error C1083: Impossible d'ouvrir le fichier includeÿ: 'leptonica/allheaders.h'ÿ: No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
python ocr tesseract python-tesseract
3个回答
2
投票

pytesseract只是对tesseract-ocr for Python的绑定。所以,如果你想在python代码中使用tesseract-ocr而不使用subprocessos模块来运行命令行tesseract-ocr命令,那么你使用pytesseract。但是,为了使用它,你必须安装tesseract-ocr

你可以这样想。您需要安装tesseract-ocr,因为它是实际运行并执行OCR的程序。但是,如果你想从python代码中运行它作为一个函数,你可以安装pytesseract包来实现这一点。所以当你运行pytesseract.image_to_string(Image.open('test-european.jpg'), lang='fra')时,它会使用提供的参数调用tesseract-ocr。结果与运行tesseract test-european.jpg -l fra相同。因此,您可以从代码中调用它,但最终,它仍然必须运行tesseract-ocr来执行实际的OCR。


0
投票

Pytesseract是tesseract二进制文件的python“包装器”。它仅提供以下功能,以及指定标志(man page):

  • get_tesseract_version返回系统中安装的Tesseract版本。
  • image_to_string将图像上的Tesseract OCR运行结果返回到字符串
  • image_to_boxes返回包含已识别字符及其框边界的结果
  • image_to_data返回包含框边界,置信度和其他信息的结果。需要Tesseract 3.05+。有关更多信息,请查看Tesseract TSV文档
  • image_to_osd返回包含有关方向和脚本检测信息的结果。

有关更多信息,请参阅project description

另一方面,tesserocr直接与Tesseract的C ++ API(APIExample)接口,后者更加灵活/复杂,并提供高级功能。


0
投票

根据我的经验,Tesserocr比Pytesseract快得多。

Tesserocr是Tesseract C ++ API的python包装器。而pytesseract是tesseract-ocr CLI的包装器。

因此,使用Tesserocr,您可以在开头或程序中加载模型,并单独运行模型(例如在循环中处理视频)。使用pytesseract,每次调用image_to_string函数时,它都会加载模型并处理图像,因此视频处理速度较慢。

要安装tesserocr,我只需输入终端pip install tesserocr

使用tesserocr

import tesserocr
from PIL import Image
api = tesserocr.PyTessBaseAPI()
pil_image = Image.open('sample.jpg')
api.SetImage(pil_image)
text = api.GetUTF8Text()

要安装pytesseract:pip install pytesseract

要运行它:

import pytesseract
import cv2
image = cv2.imread('sample.jpg')
text = pytesseract.image_to_string(image)  
© www.soinside.com 2019 - 2024. All rights reserved.