gpt4 book ai didi

java - Tess4j 不使用它的 tessdata 文件夹

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:20:38 25 4
gpt4 key购买 nike

我正在使用 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.
#

这是否意味着我需要安装 Tesseract 才能使用 tess4j?为什么?或者也许我的 tess4j tessdata 文件夹在错误的位置(它当前与我的 .java 文件一起,tess4j jar 在我设置了类路径的 lib 文件夹中)。

最佳答案

对于那些使用 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());
}

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

关于java - Tess4j 不使用它的 tessdata 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18095708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com