【问题标题】:Tesseract installation in Google colaboratoryGoogle colaboratory 中的 Tesseract 安装
【发布时间】:2018-08-05 17:00:39
【问题描述】:

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

!pip install tesseract

但是当我运行命令时

text = pytesseract.image_to_string(Image.open('cropped_img.png'))

我收到以下错误:

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

【问题讨论】:

标签: tesseract google-colaboratory


【解决方案1】:

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

这应该可以解决 TesseractNotFoundError。

【讨论】:

  • 使用pytesseract.pytesseract.tesseract_cmd = ( r'/usr/bin/tesseract' ) 为我工作。上下文:stackoverflow.com/a/62905505/8664401
  • 如何添加这个?我的意思是在哪里添加它?
【解决方案2】:

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

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

这基本上是解决方案:

! apt install tesseract-ocr
! apt install libtesseract-dev

上面安装了pytesseract 所需的依赖项。这一点非常重要,尤其是!,没有它你不能直接安装到底层操作系统。

剩下的流程比较简单:

! pip install Pillow
! pip install pytesseract

这将安装 Python 绑定。

剩下的很简单,你只需要import

import pytesseract
from PIL import ImageEnhance, ImageFilter, Image

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

希望这对某人有所帮助。

【讨论】:

  • 当我使用 Google Colab 而不是我自己的 MacBook 时,这真的很有帮助。感谢您的帖子!
【解决方案3】:

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

!sudo apt install tesseract-ocr

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

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

【讨论】:

    【解决方案4】:

    您需要安装pytesseract 而不是tesseract

    这是一个例子:

    https://colab.research.google.com/drive/1zduW1Hxv7Z_pwMFGjVauhs1dTlvZByCy

    【讨论】:

    • 我已经使用命令 "!pip install pytesseract" 安装了 pytesseract,但仍然出现相同的错误。您能否在上面的笔记本中提供一个使用 pytesseract 读取图像的示例。
    【解决方案5】:
    !sudo apt install tesseract-ocr
    
    !pip install pytesseract
    

    在使用 tesseract 之前,在您的 colab 单元中运行这两个命令。它对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-06
      • 1970-01-01
      • 2020-12-23
      • 2020-06-16
      • 2020-07-01
      • 2018-06-25
      • 2020-05-05
      相关资源
      最近更新 更多