Windows Tesseract TESSDATA_PREFIX 问题

Windows Tesseract TESSDATA_PREFIX problem

我正在用 Tesseract 制作一个 OCR 程序,但是它抛出了一个异常:

    Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory.
Failed loading language 'eng'
Tesseract couldn't load any languages!

我的 tessdata 文件夹和 traineddata 文件在我的根项目文件夹中,这是我程序的阅读部分:

public class textRecognizer {

    static Scanner scan = new Scanner(System.in);
    static String mrzText;
    static String tesseractData = "/TextRecog/tessdata";
    static Tesseract tesObj = new Tesseract();

    static {
        tesObj.setDatapath(tesseractData);
        }

    public static void main(String[] args) {
        
        float startTime = System.currentTimeMillis();
        
        try {
            mrzText = tesObj.doOCR(new File("textimage.png"));
            System.out.println("Text in file is: "+mrzText);
        }
        
        catch(TesseractException e) {
            e.printStackTrace();
        }
        System.out.println("Time taken by program is: "+String.valueOf(System.currentTimeMillis() - startTime));
    }
    
}

textimage.png也在项目文件夹中。

我试过了:

运行 C:\Users\Ege\eclipse-workspace\TextRecog>set TESSDATA_PREFIX = C:\Users\Ege\eclipse-workspace\TextRecog\tessdata 在 cmd.

正在重新下载 tesseract

已解决,问题是tesseractData字符串的目录。改为

static String tesseractData = "tessdata";

tessdata 文件夹在我的项目文件夹中,因此无需向其中写入完整目录。程序现在运行良好