【问题标题】:Tesseract OCR not working in Java on LinuxTesseract OCR 在 Linux 上的 Java 中不起作用
【发布时间】:2015-10-12 20:19:50
【问题描述】:

我在我的服务器上部署了一个战争文件,Java 在后端工作。我试图让 Tesseract 在 CentOS 上的 Java 中工作,但它根本行不通。不过,它完美地在我的 Windows localhost 上运行。我的代码是:

private void doOCR(File file) // The image file
{
    InputStream stream = new FileInputStream(file);

    ContentHandler handler = new BodyContentHandler();
    Metadata metadata = new Metadata();
    ParseContext context = new ParseContext();

    TesseractOCRConfig config = new TesseractOCRConfig();
    config.setTesseractPath(TESSERACT_PATH);
    // Path on Windows is C://Tesseract-ocr and path on Linux is /usr/local/bin
    context.set(TesseractOCRConfig.class, config);

    TesseractOCRParser tessParser = new TesseractOCRParser();       
    tessParser.parse(stream, handler, metadata, context);
    stream.close();
    System.out.println(handler.toString()); // handler.toString() prints extracted text
}

此代码适用于 Windows,但不适用于 Linux。但是,我可以从命令行执行 Tesseract,并且输出文件包含正确的文本。 Tesseract 无法在 Linux 上的 Java 上运行。我在这里有什么遗漏吗?谢谢!

【问题讨论】:

  • 你是什么意思它“只是行不通”?
  • 我的意思是 tesseract 在我的 Windows 程序中工作,在 Linux 的命令行中工作,但它不适用于我的 Linux 项目。我的 Tomcat 日志中没有任何错误,但我猜它在某处捕获异常并跳过此方法的执行。
  • Tesseract 在你的 Linux 路径上吗?你确定运行Tomcat的用户可以访问并执行它吗?

标签: java linux centos tesseract apache-tika


【解决方案1】:

好的,我发现了我的问题。在 Linux 上,tesseract 文件存储在许多不同的位置(即一些在 etc/tomcat6 中,一些在 var/lib/tomcat6 中,等等)。在我的 Windows 机器上,所有文件都存储在同一个文件夹(Tesseract-ocr)中。我在两台机器上都设置了 tesseract 可执行文件的路径,但我需要将所有 tesseract 数据文件放在同一位置。进行此更改解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多