我对 pytesseract 有疑问

Posted

技术标签:

【中文标题】我对 pytesseract 有疑问【英文标题】:I have issues with pytesseract 【发布时间】:2020-12-30 01:50:23 【问题描述】:

我有一个使用 pytesseract 的项目。我安装了 tesseract,但每次尝试运行代码时都会出现此错误。

pytesseract.pytesseract.TesseractError: (1, 'Error opening data file C:\\Users\\ekrem\\AppData\\Local\\Tesseract-OCR\\tesseract.exe/eng.traineddata 请确保 TESSDATA_PREFIX环境变量设置为您的“tessdata”目录。加载语言“eng”失败,Tesseract 无法加载任何语言!无法初始化 tesseract。')

我设置了 TESSDATA_PREFIX:

我使用的是 Windows 10。

这是我的代码:

import pytesseract
import os
import shutil


pytesseract.pytesseract.tesseract_cmd="C:\\Users\\ekrem\\AppData\\Local\\Tesseract-OCR\\tesseract.exe"
directory='C:\\Users\\ekrem\\Desktop\\resimler'
for filename in os.listdir(directory):
    b=os.path.join(directory, filename)
    if 'CRN' in pytesseract.image_to_string(b):
        print(b)
        a=pytesseract.image_to_string(b).index('CRN')
        print(pytesseract.image_to_string(b)[a-6:a-1])
    else:
        destination='C:\\Users\\ekrem\\Desktop\\fails'
        c = os.path.join(destination, filename)
        shutil.copyfile(b,c)

【问题讨论】:

说将环境变量设置为 tessdata 文件夹,但您似乎已将其设置为 .EXE 文件的完整路径。 我仍然遇到同样的错误 如果您确实将环境变量设置为 tessdata 文件夹,请更新您的问题。 我编辑了问题,我得到了同样的错误 【参考方案1】:

...\\tesseract.exe/eng.traineddata - 如果这条路径错误 - 你错误地设置了 TESSDATA_PREFIX

【讨论】:

以上是关于我对 pytesseract 有疑问的主要内容,如果未能解决你的问题,请参考以下文章

Pytesseract:FileNotFound

技术分享python验证码识别

图像_pytesseract

没有这样的文件或目录:'tesseract': 'tesseract' 即使在 pytesseract.py 中指定了在哪里可以找到 tesseract

Python验证码通过pytesser识别

pytesseract:良好的 OCR 或良好的线条 - 绝不会两者兼而有之