0

我有一个关于拼接图像的项目,我使用 opencv 2.4.5 和 java。我所有的代码都是java代码,当它是一个java项目时它运行完美。我将代码转移到 android,将 opencv-245.jar 和 opencv_java245.dll 导入我的项目,然后配置构建路径。但是当我的代码涉及 System.loadLibrary(...) 时:

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat image1= Highgui.imread( imgs.get(0).toString() , 1);
Mat image2= Highgui.imread( imgs.get(1).toString() , 1);
...

它给出了一个错误,并且无法加载 opencv 本机库(opencv_java245.dll)。我在互联网上搜索并阅读了很多东西,但没有找到答案。其中大多数是关于 android ndk 的,但我不使用它,而且我的代码不是 c++。我尝试使用 System.load(path) 但再次失败。请给我任何建议。谢谢。

更新:堆栈跟踪:

06-23 18:23:37.884: E/AndroidRuntime(443): FATAL EXCEPTION: main
06-23 18:23:37.884: E/AndroidRuntime(443): java.lang.IllegalStateException: Could not execute method of the activity
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.view.View$1.onClick(View.java:2704)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.view.View.performClick(View.java:3100)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.view.View$PerformClick.run(View.java:11644)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.os.Handler.handleCallback(Handler.java:587)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.os.Looper.loop(Looper.java:126)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.app.ActivityThread.main(ActivityThread.java:3997)
06-23 18:23:37.884: E/AndroidRuntime(443):  at java.lang.reflect.Method.invokeNative(Native Method)
06-23 18:23:37.884: E/AndroidRuntime(443):  at java.lang.reflect.Method.invoke(Method.java:491)
06-23 18:23:37.884: E/AndroidRuntime(443):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
06-23 18:23:37.884: E/AndroidRuntime(443):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
06-23 18:23:37.884: E/AndroidRuntime(443):  at dalvik.system.NativeStart.main(Native Method)
06-23 18:23:37.884: E/AndroidRuntime(443): Caused by: java.lang.reflect.InvocationTargetException
06-23 18:23:37.884: E/AndroidRuntime(443):  at java.lang.reflect.Method.invokeNative(Native Method)
06-23 18:23:37.884: E/AndroidRuntime(443):  at java.lang.reflect.Method.invoke(Method.java:491)
06-23 18:23:37.884: E/AndroidRuntime(443):  at android.view.View$1.onClick(View.java:2699)
06-23 18:23:37.884: E/AndroidRuntime(443):  ... 11 more
06-23 18:23:37.884: E/AndroidRuntime(443): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opencv_java245: findLibrary returned null
06-23 18:23:37.884: E/AndroidRuntime(443):  at java.lang.Runtime.loadLibrary(Runtime.java:425)
06-23 18:23:37.884: E/AndroidRuntime(443):  at java.lang.System.loadLibrary(System.java:554)
06-23 18:23:37.884: E/AndroidRuntime(443):  at org.myproject.stitching_android.SDCardToGridView.onClickStitching(SDCardToGridView.java:90)
06-23 18:23:37.884: E/AndroidRuntime(443):  ... 14 more
4

1 回答 1

2

基本问题是您试图在 Android 设备上加载 dll。DLL 是仅 Microsoft Windows 的库,它不能由 Android 应用程序加载。


java.lang.UnsatisfiedLinkError: Cannot load library: load_library[1108]: Library '/data/data/org.myproject.stitching_android/lib/opencv_java245.dll' not found

意味着您的应用找不到文件,即使找到文件也无法加载,因为 Android 不支持 DLL

于 2013-06-23T18:10:15.897 回答