在安装完tesseract, pytesseract后执行测试命令,发现打印如下错误:
Error opening data file \Program Files (x86)\Tesseract-OCR\tessdata/eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory. Failed loading language 'eng' Tesseract couldn't load any languages! Could not initialize tesseract.
不过,费了大半天劲,终于找到了一个靠谱的解决方案。就是在环境变量中新增一个变量TESSDATA_PREFIX,使该变量的值为
D:\Profession\Tesseract-OCR\tessdata 该路径值。我开始是在path变量下,把路径值放在了该变量下,肯定失败。另外,还要重启一下,才能生效。
测试demo
--encoding:utf-8--
import pytesseract
from PIL import Image
# image = Image.open(".png")
image = Image.open('./images/yanzhengma.png')
result = pytesseract.image_to_string(image)
print(result)
网友评论