gpt4 book ai didi

java - Tesseract/Tess4J 在 Mac OS X 上崩溃:有问题的框架:C [libtesseract.dylib+0xcf72] tesseract::TessResultRenderer::~TessResultRenderer()+0x10

转载 作者:行者123 更新时间:2023-12-01 09:18:54 24 4
gpt4 key购买 nike

我在 Mac OS X 上使用 Tesseract 和 Java 包装器库 Tess4J 运行一个简单的程序。尝试了 JDK7 和 JDK8。

该代码对图像进行 OCR 操作并从中创建 PDF。该代码可以正常工作并执行其应该执行的操作(可以很好地创建 pdf)。但最后,我收到了 Mac 的崩溃报告。

private static void testTesseract() throws Exception {
File imageFile = new File("/Users/mln/Desktop/urkunde.jpg");
ITesseract instance = new Tesseract(); // JNA Interface Mapping

// http://tess4j.sourceforge.net/tutorial/

instance.setDatapath("/Users/mln/Desktop/tessdata");
instance.setLanguage("deu");

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

List<ITesseract.RenderedFormat> list = new ArrayList<ITesseract.RenderedFormat>();
list.add(ITesseract.RenderedFormat.PDF);
File pdfFile = new File("/Users/mln/Desktop/urkunde.jpg");
instance.createDocuments(pdfFile.getAbsolutePath(), "/Users/mln/Desktop/urkunde", list);

}

导致崩溃的行是最后一行:

instance.createDocuments(pdfFile.getAbsolutePath(), "/Users/mln/Desktop/urkunde", list);

控制台输出:

Warning in pixReadMemJpeg: work-around: writing to a temp file
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00000001295c9f72, pid=6336, tid=5891
#
# JRE version: Java(TM) SE Runtime Environment (8.0_31-b13) (build 1.8.0_31-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.31-b07 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# C [libtesseract.dylib+0xcf72] tesseract::TessResultRenderer::~TessResultRenderer()+0x10
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/mln/Projects/jackrabbit-client/hs_err_pid6336.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

和崩溃报告:

Process:               java [6336]
Path: /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin/java
Identifier: net.java.openjdk.cmd
Version: 1.0 (1.0)
Code Type: X86-64 (Native)
Parent Process: idea [81650]
Responsible: java [6336]
User ID: 501

Date/Time: 2016-10-28 11:09:35.377 +0200
OS Version: Mac OS X 10.11.6 (15G1004)
Report Version: 11
Anonymous UUID: 6CF2EEC0-C9B5-315F-EB2E-5AEBDF0094FD

Sleep/Wake UUID: F9F2D823-9374-4EC4-B8FD-9342826E1A37

Time Awake Since Boot: 600000 seconds
Time Since Wake: 10000 seconds

System Integrity Protection: enabled

Crashed Thread: 4

Exception Type: EXC_BAD_ACCESS (SIGABRT)
Exception Codes: EXC_I386_GPFLT
Exception Note: EXC_CORPSE_NOTIFY

Application Specific Information:
abort() called

pastebin 上的完整输出:http://pastebin.com/v9gPd4hk

最佳答案

我自己还没有测试过,但看起来 createDocuments 调用了 init()dispose()doOCR() 也是如此>。您可能想尝试重写这些方法以仅调用一次。有点盲目,但似乎很合理。

@Override
public void createDocuments(String[] filenames, String[] outputbases, List<RenderedFormat> formats) throws TesseractException {
if (filenames.length != outputbases.length) {
throw new RuntimeException("The two arrays must match in length.");
}

init();
setTessVariables();

try {
for (int i = 0; i < filenames.length; i++) {
File workingTiffFile = null;
try {
String filename = filenames[i];

// if PDF, convert to multi-page TIFF
if (filename.toLowerCase().endsWith(".pdf")) {
workingTiffFile = PdfUtilities.convertPdf2Tiff(new File(filename));
filename = workingTiffFile.getPath();
}

TessResultRenderer renderer = createRenderers(outputbases[i], formats);
createDocuments(filename, renderer);
TessDeleteResultRenderer(renderer);
} catch (Exception e) {
// skip the problematic image file
logger.error(e.getMessage(), e);
} finally {
if (workingTiffFile != null && workingTiffFile.exists()) {
workingTiffFile.delete();
}
}
}
} finally {
dispose();
}
}

关于java - Tesseract/Tess4J 在 Mac OS X 上崩溃:有问题的框架:C [libtesseract.dylib+0xcf72] tesseract::TessResultRenderer::~TessResultRenderer()+0x10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40301936/

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