Tess4j不使用它的tessdata文件夹

Kiw*_*ird 7 java tesseract

我正在使用tess4j,Tesseract的java包装器.我也安装了正常的Tesseract.我不太确定tess4j是如何工作的,但由于它附带了一个tessdata文件夹,我可以假设您将语言数据文件放在那里.但是,tess4j仅在语言数据文件位于"真实"tessdata文件夹(tesseract附带的文件夹,而不是tess4j)中时才起作用.如果我删除该文件夹,我收到此错误消息:

Error opening data file C:\Program Files\Tesseract-OCR\tessdata/jpn.trained
data
Please make sure the TESSDATA_PREFIX environment variable is set to the par
ent directory of your "tessdata" directory.
Failed loading language 'jpn'
Tesseract couldn't load any languages!
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x631259dc, pid=5108, tid=
10148
#
# JRE version: 7.0_06-b24
# Java VM: Java HotSpot(TM) Client VM (23.2-b09 mixed mode, sharing windows
-x86 )
# Problematic frame:
# C  [libtesseract302.dll+0x59dc]  STRING::strdup+0x467c
#
# Failed to write core dump. Minidumps are not enabled by default on client
 versions of Windows
#
# An error report file with more information is saved as:
# D:\School\Programs\OCRTest\v1.0.0\hs_err_pid5108.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Run Code Online (Sandbox Code Playgroud)

这是否意味着我需要安装Tesseract才能使用tess4j?为什么?或莫比我tess4j tessdata文件夹是在错误的地方(这是目前我的.java文件中,tess4j罐子中,我设置了类路径lib文件夹).

Chr*_*s13 7

对于那些使用 maven 并且不喜欢使用全局变量的人,这对我有用:

File imageFile = new File("C:\\random.png");
Tesseract instance = Tesseract.getInstance();

//In case you don't have your own tessdata, let it also be extracted for you
File tessDataFolder = LoadLibs.extractTessResources("tessdata");

//Set the tessdata path
instance.setDatapath(tessDataFolder.getAbsolutePath());

try {
    String result = instance.doOCR(imageFile);
    System.out.println(result);
} catch (TesseractException e) {
    System.err.println(e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)

这里找到,用 maven 测试 -> net.sourceforge.tess4j:tess4j:3.4.1,链接也使用 1.4.1 jar


ssc*_*ass 4

让您TESSDATA_PREFIX environment variable指向 Tess4j 的 tessdata 文件夹。

通常,您在系统安装过程中设置这些变量,但您可能会在这里找到解决方案:How do I setenvironment variables from Java?

您必须在运行应用程序的系统上执行此操作,因为 tessdata.dll取决于此环境变量。