ocr - 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)
解决方案
安装:
!sudo apt install tesseract-ocr
改变:
pytesseract.pytesseract.tesseract_cmd = r'/usr/local/bin/pytesseract'
至:
pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'
推荐阅读
- python - 为什么如果第一个元素为True,OR返回True,但即使第一个元素为True,ANY仍会检查所有元素
- java - 如何通过java中的两种方法运行变量
- typescript - 如何在控制器中注入 ts-mockito 模拟对象
- python - python中的lookat矩阵乘法函数对于一个龙精湛的opengl示例是什么?
- jquery - 如何查询 MYSQL 表以获取总体和过去一年内的列出现次数?
- python - 获取 Python Flask 以从 json/dictionary 返回值
- boolean-logic - 需要关于解码器的解释
- python - 如何在图例的同一行上放置多个具有相同标签的符号?
- reactjs - React/Express 在本地读取但在 Heroku 中找不到
- jquery - jquery最接近和克隆问题