centos Tesseract OCR无法在Linux上的Java中运行

xsuvu9jc  于 2022-11-08  发布在  Linux
关注(0)|答案(1)|浏览(228)

我在我的服务器上部署了一个war文件,Java在后台运行。我试图让Tesseract在CentOS上用Java运行,但它根本不起作用。不过,它在我的Windows本地主机上运行得 * 完美 *。我拥有的代码是:

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中运行。这里有什么我遗漏的吗?谢谢!

yzckvree

yzckvree1#

好了,我解决了我的问题。在Linux上,tesseract文件存储在许多不同的位置(例如,一些文件在etc/tomcat 6中,一些文件在var/lib/tomcat 6中,等等)。在我的Windows计算机上,所有文件都存储在同一个文件夹中(Tesseract-ocr)。我在两台机器上都设置了tesseract可执行文件的路径,但是我 * 还 * 需要将所有的tesseract数据文件放在同一个位置。

相关问题