首页 > 解决方案 > TesseractError: (2, 'Usage: pytesseract [-l lang] input_file') 错误

问题描述

我收到错误 TesseractError: (2, 'Usage: pytesseract [-l lang] input_file')。使用 !sudo apt install 但在 colab 中仍然出现错误。它是我正在尝试阅读的 JPG。

- - - - - - - - - - - - - - -代码 - - - - - - - - - - -----------------

! apt install tesseract-ocr
! apt install libtesseract-dev
! sudo apt install tesseract-ocr
! pip install Pillow
! pip install pytesseract
import pytesseract
import shutil
import os
import cv2
import random
from google.colab import files
from io import BytesIO
from PIL import Image,ImageFilter
!pip install pdf2image
!apt-get install -y poppler-utils
from pdf2image import convert_from_path
#from google.colab import drive
!sudo apt install tesseract-ocr
!pip install pytesseract
!pip install tesseract

pytesseract.pytesseract.tesseract_cmd = r'/usr/local/bin/pytesseract'
image_path_in_colab = 'Pillow block drawing.jpg'
img = cv2.imread('Pillow block drawing.jpg')
custom_config = r'-l eng --psm 6'
pytesseract.image_to_string(img, config=custom_config)
extractedInformation = pytesseract.image_to_string(Image.open(image_path_in_colab))
print(extractedInformation)

标签: ocrtesseract

解决方案


安装:

!sudo apt install tesseract-ocr

改变:

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

至:

pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'

推荐阅读