通过命令行与JNI调用 [英] Invoking via command line versus JNI

查看:87
本文介绍了通过命令行与JNI调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Java Application Server调用tesseract OCR(它是C ++中的一个开放库,它可以进行光学字符识别).现在,它很容易使用Runtime.exec()运行可执行文件.基本逻辑是

I need to invoke tesseract OCR (its an open source library in C++ that does Optical Character Recognition) from a Java Application Server. Right now its easy enough to run the executable using Runtime.exec(). The basic logic would be

  1. 将当前保存在内存中的图像保存到文件(.tif)
  2. 将图像文件名传递到tesseract命令行程序.
  3. 使用FileReader从Java读取输出文本文件.

通过为Tesseract编写JNI包装器,我可能会在性能方面获得多少改进?不幸的是,在Linux中没有一个开源的JNI包装器.我将不得不自己做,并且想知道所获得的收益是否值得开发成本.

How much improvement in terms of performance am I likely to get by writing a JNI wrapper for Tesseract? Unfortunately there is not an open source JNI wrapper that works in Linux. I would have to do it myself and am wondering about whether the benefit is worth the development cost.

推荐答案

很难说这是否值得.如果您假设通过JNI在过程中完成,则OCR代码可以直接访问映像数据而不必将其写入文件,那么它肯定会消除那里的任何磁盘I/O约束.

It's hard to say whether it would be worth it. If you assume that if done in-process via JNI, the OCR code can directly access the image data without having to write it to a file, then it would certainly eliminate any disk I/O constraints there.

我建议使用更简单的方法,并且仅在性能不可接受时才采用JNI选项.至少到那时,您将能够进行一些基准测试并估计可能实现的性能提升.

I'd recommend going with the simpler approach and only undertaking the JNI option if performance is not acceptable. At least then you'll be able to do some benchmarking and estimate the performance gains you might be able to realize.

这篇关于通过命令行与JNI调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆