【python】调用tesseract时报错
tesseract
tesseract-ocr/tesseract: 是一个开源的光学字符识别(OCR)引擎,适用于从图像中提取和识别文本。特点是可以识别多种语言,具有较高的识别准确率,并且支持命令行和API调用。
项目地址:https://gitcode.com/gh_mirrors/te/tesseract
免费下载资源
·
import pytesseract
from PIL import Image
image = Image.open('image.png')
print(pytesseract.image_to_string(image))
第一次通过pytesseract调用tesseract时,运行后报错:
- Traceback(mostrecentcalllast):
- File "d:\Python36\lib\site-packages\pytesseract\pytesseract.py", line 260, in get_tesseract_version
- [tesseract_cmd, '--version'], stderr=subprocess.STDOUT
- .....(部分省略)
- pytesseract.pytesseract.TesseractNotFoundError: tesseract.exe is not installed or it's not in your path
根据第4行报错提示,初步怀疑是环境变量的原因
于是检查了本机环境变量的设置,发现都设置无误
再进行判断查看了第2、3行的报错信息:tesseract_cmd --version
于是进入python包lib\site-packages\pytesseract\ 修改了pytesseract.py里面的这段源码:
numpy_installed = find_loader('numpy') is not None
if numpy_installed:
from numpy import ndarray
# CHANGE THIS IF TESSERACT IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
tesseract_cmd = 'tesseract'
RGB_MODE = 'RGB'
OSD_KEYS = {
修改为下面这样:
numpy_installed = find_loader('numpy') is not None
if numpy_installed:
from numpy import ndarray
# CHANGE THIS IF TESSERACT IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
#tesseract_cmd = 'tesseract'
tesseract_cmd = r'D:\Program Files (x86)\Tesseract-OCR\tesseract.exe'
RGB_MODE = 'RGB'
OSD_KEYS = {
在此运行,能正常识别图片的文字。
GitHub 加速计划 / te / tesseract
60.1 K
9.29 K
下载
tesseract-ocr/tesseract: 是一个开源的光学字符识别(OCR)引擎,适用于从图像中提取和识别文本。特点是可以识别多种语言,具有较高的识别准确率,并且支持命令行和API调用。
最近提交(Master分支:2 个月前 )
bc490ea7
Don't check for a directory, because a symbolic link is also allowed.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
4 个月前
2991d36a - 4 个月前
更多推荐
已为社区贡献4条内容
所有评论(0)