英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论