Windows Tesseract TESSDATA_PREFIX问题

huangapple go评论132阅读模式
英文:

Windows Tesseract TESSDATA_PREFIX problem

问题

以下是您要翻译的内容:

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

请确保TESSDATA_PREFIX环境变量已设置为您的“tessdata”目录。
加载语言失败 'eng'
Tesseract 无法加载任何语言!

我的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("文件中的文本是:"+mrzText);
        }

        catch(TesseractException e) {
            e.printStackTrace();
        }
        System.out.println("程序执行时间:"+String.valueOf(System.currentTimeMillis() - startTime));
    }
    
}

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

我尝试过:

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

重新下载Tesseract。
英文:

i am making a OCR program with Tesseract, however it throws an exception as:

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

My tessdata folder and traineddata files are inside my root project folder, here is a reading part of my program:

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 is also in the project folder.

I tried:

Running C:\Users\Ege\eclipse-workspace\TextRecog>set TESSDATA_PREFIX = C:\Users\Ege\eclipse-workspace\TextRecog\tessdata in cmd.

Redownloading tesseract

答案1

得分: 0

已解决,问题在于 "tesseractData" 字符串的目录。将其更改为

static String tesseractData = "tessdata";

tessdata 文件夹位于我的项目文件夹中,因此无需编写完整目录。程序现在正常工作。

英文:

Solved, the problem is directory of tesseractData string. Changed it to

static String tesseractData = "tessdata";

tessdata folder is in my project folder so there is no need to write full directory to that. Program is working fine now

huangapple
  • 本文由 发表于 2020年6月29日 14:01:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/62632128.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定