导出使用opencv的可执行文件 [英] Exporting Executable jar file that uses opencv

查看:171
本文介绍了导出使用opencv的可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在eclipse中导出时,我选择将需要的库转换为生成的jar。
该jar文件仅在我的机器上工作。但是,当我在其他机器上测试时,它会提供这种异常:

While exporting in eclipse I choose "Package required libraries into generated jar". The jar file works only in my machine. However, when I test it on other machine it gives this Exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopencv_core in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:593)
at com.googlecode.javacpp.Loader.load(Loader.java:489)
at com.googlecode.javacpp.Loader.load(Loader.java:431)
at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:136)
at mains.<clinit>(mains.java:25)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:266)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)


推荐答案

简短答案



您必须安装OpenCV在 JavaCV要求)和系统上的JavaCV,以使用JavaCV。由于您可能已将其安装在计算机上进行开发,因此该应用程序可以工作,但另一台机器可能尚未安装,因此 jar 无法正常工作。

Short answer

You must install OpenCV (as mentioned in JavaCV requirements) and JavaCV on the system in order to use JavaCV. As you probably installed them for development on your computer the application work, but the other machine probably has not them installed and thus the jar does'nt work.

问题不在于您的 jar中正确包含的JavaCV库如下所示:

The problem is not the JavaCV library, which appears to be correctly included into your jar as shown by the lines:

at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:593)
at com.googlecode.javacpp.Loader.load(Loader.java:489)
at com.googlecode.javacpp.Loader.load(Loader.java:431)
at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:136)

事实上,JavaCV是建立在OpenCV之上的。 OpenCV是一个C ++库,从Java使用它的唯一方法是使用JNI调用。

The fact is JavaCV is build on top of OpenCV. OpenCV being a C++ library, the only way to use it from Java is to use JNI calls.

JNI需要两个组件:

JNI require two components:


  • 包含调用本机库的java方法的java库(通常带扩展名 *。jar

  • 一个本地库(通常使用扩展名 *。so 为linux或 *。dll 为Windows) 做工作,在这种情况下,使用OpenCV库

  • A java library (usually with extension *.jar) containing java method that calls native library
  • A native library (usually with extension *.so for linux or *.dll for windows) that "do the work", in this case that "use OpenCV library"

第一个由JavaCV提供并包含在您的 jar 应用程序。第二个是系统依赖(Os,架构,...),并且必须进入java库路径。

The first one is provided by JavaCV and included into your jar application. The second one is system dependent (Os, architecture, ...) and must be into the java library path.

这是实际的错误:它找不到 libjniopencv_core.so into java.library.path 。 JavaCV也提供了 jniopencv_core 库,但安装在系统上的某个位置(例如 / usr / lib / 因此不包括在最终的 jar 中。

This is the actual error: it can not find libjniopencv_core.so into java.library.path. The jniopencv_core library is provided by JavaCV too but is installed somewhere on the system (/usr/lib/ for instance) and thus not included into the final jar.

即使您找到一种方法将其包含到最终应用程序中,此库将需要使用系统上未安装的OpenCV库。总结需求:

Even if you find a way to include it into the final application, this library will need to use OpenCV libraries which are not installed on the system too. To summarize the needs:


  1. JavaCV java库,将调用(使用JNI):

  2. JavaCV本地库,将使用:

  3. OpenCV库,这将真正做到这一点。

  1. JavaCV java library, that will call (with JNI):
  2. JavaCV native library, that will use:
  3. OpenCV libraries, that will really do the work.

没有这一点,应用程序将无法正常工作。因此,OpenCV和JavaCV必须安装到系统中。

Without one of this point the application will not work. Thus OpenCV and JavaCV must be installed into the system.

这篇关于导出使用opencv的可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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