(2, '用法: pytesseract [-l lang] input_file') 在 Google Colab 上

ard*_*yan 4 python python-tesseract google-colaboratory

我正在尝试在 Google Colab 中运行 Tesseract:

!sudo apt install tesseract-ocr
!pip install pytesseract

import pytesseract
import shutil
import os
import random
try:
 from PIL import Image
except ImportError:
 import Image

from google.colab import files
uploaded = files.upload()

extractedInformation = pytesseract.image_to_string(Image.open('aaa.png'))
print(extractedInformation)
Run Code Online (Sandbox Code Playgroud)

我尝试在我正在上传的图像('aaa.png')上运行,但它运行此错误:

TesseractError: (2, 'Usage: pytesseract [-l lang] input_file')
Run Code Online (Sandbox Code Playgroud)

从几乎相同(仍未解决)的帖子中搜索,我尝试了以下代码,但仍然无法正常工作:

pytesseract.pytesseract.tesseract_cmd = (
    r'/usr/local/bin/tesseract'
)
Run Code Online (Sandbox Code Playgroud)

我尝试访问 pytesseract 文件夹,但运行此错误:

在此输入图像描述

PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/pytesseract/pytesseract.py'
Run Code Online (Sandbox Code Playgroud)

ard*_*yan 6

通过使用解决:

pytesseract.pytesseract.tesseract_cmd = (
    r'/usr/bin/tesseract'
)
Run Code Online (Sandbox Code Playgroud)