【问题标题】:Tesseract / Tess4J crashes on Mac OS X: Problematic frame: C [libtesseract.dylib+0xcf72] tesseract::TessResultRenderer::~TessResultRenderer()+0x10Tesseract / Tess4J 在 Mac OS X 上崩溃:有问题的框架:C [libtesseract.dylib+0xcf72] tesseract::TessResultRenderer::~TessResultRenderer()+0x10
【发布时间】:2016-10-28 09:20:07
【问题描述】:

我在 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

【问题讨论】:

  • 该错误似乎源自 Leptonica。可能与您的 libjpeg 库有关。
  • @nguyenq 似乎是 MacOS X 的一些更普遍的问题。我尝试从源代码构建项目,但在单元测试中也已经失败,错误为 [junit] 10:04:57.140 [main] ERROR net.sourceforge.tess4j.Tesseract1 - Unable to load library 'gs': Native library (darwin/libgs.dylib) not found in resource path。日志:pastebin.com/Ba4wUYYu,这似乎也是一个已知问题:stackoverflow.com/questions/21394537/…
  • 对于gs问题,您需要安装GhostScript; Tess4J 依赖它来读取 PDF 文件。
  • 好的。 tess4j 中的 readme.html 内容为:“Tesseract 3.04、Leptonica 1.71(通过 Lept4J)和 Ghostscript 9.16 32 位和 64 位 DLL、英语语言数据和示例图像与库捆绑在一起。”所以我认为它们已经包含在内了。
  • 已安装 GS,但构建仍然失败并出现其他错误。完整日志:pastebin.com/ZznbkW8v - 不确定是否是这条线导致了它java(16778,0x70000021a000) malloc: *** error for object 0x7fa6cf8e3e78: pointer being freed was not allocated。我在日志中看到的另一个错误是:Error looking up function 'l_bootnum_gen1': dlsym(0x7fe4f0d318d0, l_bootnum_gen1): symbol not found

标签: java macos crash tesseract tess4j


【解决方案1】:

我自己没有测试过,但它看起来像 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();
    }
}

【讨论】:

  • 谢谢,我明天试试。不幸的是,我不能只扩展 Tesseract 类,因为 createRenderers 和 createDocuments 方法是私有的而不是受保护的。所以我需要构建整个东西。
  • 幸运的是,乍一看,它看起来还不错。一点复制和粘贴。祝你好运。
  • 我尝试从源代码构建项目,但这在单元测试中也已经失败,错误为[junit] 10:04:57.140 [main] ERROR net.sourceforge.tess4j.Tesseract1 - Unable to load library 'gs': Native library (darwin/libgs.dylib) not found in resource path。日志:pastebin.com/Ba4wUYYu,这似乎也是一个已知问题:stackoverflow.com/questions/21394537/…
  • 我将在 MacOS X 以外的其他系统上对其进行测试,看看它是否可以在那里工作。如果是这样,我可能暂时忽略它,因为最终应用程序将在 Linux 上运行,而不是在 Mac 上运行。这样我也可以坚持使用 Maven 存储库中的原始库。
  • init()dispose() 方法在不同点被调用,不仅在 doOCR()createDocuments() 中,而且在 getSegmentedRegionsgetWords() 中。在应用程序中使用库时,我永远不知道先调用哪个。我试图注释掉 createDocuments 中的方法并构建运行 somt 单元测试的 Tess4J 项目。它因 NullPointer 异常而失败。在doOCR() 中将它们注释掉似乎也会导致 NullPointerExceptions。我认为,如果问题出在initdispose 上,这些方法需要进行某种检查是否已经启动。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-24
  • 1970-01-01
相关资源
最近更新 更多