在 Google colaboratory 中安装 Tesseract

Pro*_*jit 6 tesseract google-colaboratory

我已经使用命令在 Google colab 中安装了 tesseract

!pip install tesseract
Run Code Online (Sandbox Code Playgroud)

但是当我运行命令时

text = pytesseract.image_to_string(Image.open('cropped_img.png'))
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

TesseractNotFoundError: tesseract 未安装或不在您的路径中

小智 9

添加 pytesseract.pytesseract.tesseract_cmd = r'/usr/local/bin/pytesseract'

这应该可以解决 TesseractNotFoundError。


小智 7

在使用 pytesseract 包装器之前,您必须先安装 tesseract 引擎。您可以使用以下方法在 Google colab 上安装该引擎:

!sudo apt install tesseract-ocr
Run Code Online (Sandbox Code Playgroud)

您可以在以下位置找到示例:

https://github.com/labdeeman7/document-ocr/blob/master/classification%20via%20NLP%20and%20information%20extraction.ipynb


Sri*_*kar 6

这可能有多种原因,但通常是因为您没有C可用于 tesseract的库。即使pytesseract是必需的,它也只是解决方案的一半。

您基本上需要安装适用于 linux 的 tesseract 包以及 Python 绑定。

这基本上是解决方案:

! apt install tesseract-ocr
! apt install libtesseract-dev
Run Code Online (Sandbox Code Playgroud)

以上安装了所需的依赖项pytesseract。这非常重要,尤其是如果!没有它,您将无法直接安装到底层操作系统。

该过程的其余部分相对简单:

! pip install Pillow
! pip install pytesseract
Run Code Online (Sandbox Code Playgroud)

这将安装 Python 绑定。

其余的相当简单,您需要做的就是import

import pytesseract
from PIL import ImageEnhance, ImageFilter, Image
Run Code Online (Sandbox Code Playgroud)

然后你就可以让魔法发生了。

希望这有助于某人。