Pytesseract 和 Tesserocr 有什么区别?

Sou*_*iri 8 python ocr tesseract python-tesseract

我在 Windows 10 中使用 Python 3.6 并且已经安装了Pytesseract,但我在代码中发现了Tesserocr,顺便说一下我无法安装。有什么不同?

小智 21

根据我的经验,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()
Run Code Online (Sandbox Code Playgroud)

要安装pytesseract: pip install pytesseract

运行它:

import pytesseract
import cv2
image = cv2.imread('sample.jpg')
text = pytesseract.image_to_string(image)  
Run Code Online (Sandbox Code Playgroud)


Nov*_*vak 3

pytesseracttesseract-ocr仅是Python 的绑定。tesseract-ocr因此,如果您想在 python 代码中使用而不使用 usingsubprocessosmodule 来运行命令行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。

  • 这并没有回答什么是 tesserocr,它与 tesseract-ocr 不同,如 /sf/answers/3947105081/ 中所述 (6认同)