【发布时间】:2019-03-27 14:08:40
【问题描述】:
在尝试使用 pytesseract 在 windows 10 上安装和使用 tesseract 时出现错误:
File "C:\ProgramData\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 194, in run_tesseract
raise TesseractError(status_code, get_errors(error_string))
TesseractError: (1, 'Error opening data file \\Program Files (x86)\\Tesseract-OCR\\eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'eng\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')
我尝试重新安装 tesseract。 我已将 C:\Program Files (x86)\Tesseract-OCR 设置为 PATH 环境变量 我已将 TESSDATA_PREFIX 添加到 C:\Program Files (x86)\Tesseract-OCR\tessdata 我已经验证了当我在 CMD 中输入“tesseract”时
我使用的代码:
import cv2
import pytesseract
# Uncomment the line below to provide path to tesseract manually
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe"
# Define config parameters.
# '-l eng' for using the English language
# '--oem 1' for using LSTM OCR Engine
config = ('-l eng --oem 1 --psm 3')
# Read image from disk
im = cv2.imread("Serie1/NL83LHL9.JPG", cv2.IMREAD_COLOR)
# Run tesseract OCR on image
text = pytesseract.image_to_string(im, config=config)
# Print recognized text
print(text)
结果:
CMD > tesseract : 显示 tesseract 界面
【问题讨论】:
-
确实看起来有点奇怪。您可以尝试的一件事是将 tessdata 路径添加到您的配置中 -
config = r'--tessdata-dir "C:\Program Files (x86)\Tesseract-OCR\tessdata" -l eng --oem 1 --psm 3' -
冒着听起来缺乏经验的风险:我应该将它添加到我拥有的众多配置文件中的哪个?
-
你有行
config = ('-l eng --oem 1 --psm 3')。用我建议的替换它。 -
确实成功了!非常感谢您的帮助。
标签: python python-3.x tesseract python-tesseract