在尝试使用pytesseract在python上安装和使用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设置为已将TESSDATA_PREFIX添加到C:\ Program Files(x86)\ Tesseract-OCR \ tessdata的PATH系列变量我已经确认当我输入'tesseract'时在CMD工作
我使用的代码:
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界面
pytesseract.pytesseract.tesseract_cmd = r'C:/Program Files (x86)/Tesseract-OCR/tesseract'
солведидмитрийЗ。
确实看起来有点奇怪。您可以尝试的一件事是将tessdata路径添加到您的配置 -
config = r'--tessdata-dir "C:\Program Files (x86)\Tesseract-OCR\tessdata" -l eng --oem 1 --psm 3'