繁体   English   中英

使用 PyTesseract 从图像中识别文本时出现问题

[英]Problem occurred when using PyTesseract to recognize text from an image

我试图为我们的学校网站制作一个自动登录程序,这需要从验证码中识别文本。 所以我从pip安装了pytesseract ,并在PyCharm中运行了程序:(图片在目录/Users/macintosh/Documents/PythonOutputs/2.jpg


import pytesseract

from PIL import Image

image = Image.open("/Users/macintosh/Documents/PythonOutputs/2.jpg")

text = pytesseract.image_to_string(image)

print(text)

但是出现了这个错误:

回溯(最近一次通话):文件“/Users/macintosh/Library/Preferences/PyCharmCE2018.2/scratches/scratch_3.py”,第 5 行,文本 = pytesseract.image_to_string(image)

文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytesseract/pytesseract.py”,第 294 行,在 image_to_string 中 return run_and_get_output(*args)

文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytesseract/pytesseract.py”,第202行,在run_and_get_output run_tesseract(**kwargs)

文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytesseract/pytesseract.py”,第 178 行,在 run_tesseract 中引发 TesseractError(status_code, get_errors(error_string))

pytesseract.pytesseract.TesseractError: (2, '用法:python pytesseract.py [-l lang] input_file')

有什么问题?

好吧,虽然你的错误信息不是很清楚,但我敢打赌(从你的行为来看)你还没有安装Tesseract本身。

在 pytessaract 文档中,它指出:

Python-tesseract 是 Google 的 Tesseract-OCR 引擎的包装器。

所以你应该安装实际的程序(即 Tesseract)来完成这项工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM