我正在使用tess4j,这是Tesseract的java包装器。我还安装了普通的Tesseract。我不太清楚tess4j是如何工作的,但是由于它附带了tessdata文件夹,所以我可以假设您会将语言数据文件放在那里。但是,只有当语言数据文件位于“真正的”tessdata文件夹(与tesseract一起提供的文件夹,而不是tess4j)时,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 jars位于我设置了类路径的lib文件夹中)。
发布于 2013-08-07 08:45:44
让您的TESSDATA_PREFIX environment variable指向Tess4j的tessdata文件夹。
通常在系统安装过程中设置这些变量,但是您可能在这里找到一个解决方案:如何从Java中设置环境变量?
您必须在运行应用程序的系统上这样做,因为tessdata .dll依赖于这个环境变量。
发布于 2017-10-06 00:31:54
对于那些使用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());
}找到了这里,并使用maven -> net.Sourceabiet.tess4j:tess4j:3.4.1进行了测试,该链接也使用1.4.1JAR
发布于 2013-08-07 23:20:43
如果定义了TESSDATA_PREFIX环境变量,它将覆盖所有内容,包括由init或setDatapath设置的变量;但是,当应用程序可以指定其tessdata文件夹的位置时,这种情况在不久的将来可能会发生变化。
http://code.google.com/p/tesseract-ocr/issues/detail?id=938
https://groups.google.com/forum/#!topic/tesseract-ocr/bkJwI8WmxSw
https://stackoverflow.com/questions/18095708
复制相似问题