在google colab中运行时pytesseract出错

问题描述 投票:0回答:1

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

!pip3 install pytesseract
!pip3 install tesseract-ocr
!sudo apt install libtesseract-dev

然后我运行命令

from pytesseract import image_to_string
import pytesseract

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

pytesseract.image_to_string(img,  lang='eng', config=r'--oem 3 --psm 7')

然后我得到了错误

---------------------------------------------------------------------------
TesseractError                            Traceback (most recent call last)
<ipython-input-42-3e07674434a3> in <module>()
      3 
----> 4 pytesseract.image_to_string(im_bw,  lang='eng', config=r'--oem 3 --psm 7')

3 frames
/usr/local/lib/python3.6/dist-packages/pytesseract/pytesseract.py in run_tesseract(input_filename, output_filename_base, extension, lang, config, nice, timeout)
    234     with timeout_manager(proc, timeout) as error_string:
    235         if proc.returncode:
--> 236             raise TesseractError(proc.returncode, get_errors(error_string))
    237 
    238 

TesseractError: (2, 'Usage: pytesseract [-l lang] input_file')
python-3.x tesseract google-colaboratory opencv3.0 python-tesseract
1个回答
0
投票

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

img = r“/content/gdrive/MyDrive/images.jpg”

结果 = pytesseract.image_to_string(Image.open(img))) 打印(结果)

您应该在此行之前指定“img 路径”, pytesseract.image_to_string(img, lang='eng', config=r'--oem 3 --psm 7')

© www.soinside.com 2019 - 2024. All rights reserved.