【问题标题】:how to fix a erro python tesseract error?如何修复错误 python tesseract 错误?
【发布时间】:2021-11-20 12:21:46
【问题描述】:

我需要使用 python tesseract 从照片中提取文本:

import pytesseract
from PIL import Image


img = Image.open('stest.png')
pytesseract.pytesseract.tesseract_cmd = 'D:\\python\\venv\\Scripts\\pytesseract.exe'

file_name = img.filename
file_name = file_name.split(".")[0]


text = pytesseract.image_to_string(img,lang=None, config='')
print(text)

with open(f'{file_name}.txt', 'w') as text_file:
    text_file.write(text)

但错误似乎与我的代码无关:

 Traceback (most recent call last):
  File "D:\python\pybotavito\main.py", line 13, in <module>
    text = pytesseract.image_to_string(img,lang=None, config='')
  File "D:\python\venv\lib\site-packages\pytesseract\pytesseract.py", line 413, in image_to_string
    return {
  File "D:\python\venv\lib\site-packages\pytesseract\pytesseract.py", line 416, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),
  File "D:\python\venv\lib\site-packages\pytesseract\pytesseract.py", line 284, in run_and_get_output
    run_tesseract(**kwargs)
  File "D:\python\venv\lib\site-packages\pytesseract\pytesseract.py", line 260, in run_tesseract
    raise TesseractError(proc.returncode, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (2, 'Usage: pytesseract [-l lang] input_file')

【问题讨论】:

    标签: python tesseract python-tesseract


    【解决方案1】:

    来自pytesseract的README页面,

    # If you don't have tesseract executable in your PATH, include the following:
    pytesseract.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'
    # Example tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract'
    

    此行必须指向tesseract 可执行文件,而不是pytesseract python 可执行文件。尝试设置正确的可执行路径。在相应行下面的注释中有一个关于在哪里可以找到可执行文件的示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      • 2021-08-14
      • 2011-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多