opencv - 在OpenCV示例中,无法链接本地库

  显示原文与译文双语对照的内容
0 0

我OpenCV代码( C++中),我想使用Android 。 为此我不得不用 Android NDK 。 我下载 OpenCV包for Android开发 ( ver 。 2 ),并完成了所有的步骤来执行手动.4 。0 。 basic示例( 仅限Java API ) 运行没有出现问题。 样例#3 ( Tutorial 3 ( Advanced ) 添加Native OpenCV ) 正确ndk构建器生成的。 但当我从eclipse运行/调试了各个设备上都会获得异常:

Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/samples/tutorial3/Sample3View;

在这一行:

System.loadLibrary("native_sample");

以下是logcat日志已满:

05-31 23:41:45.976: W/ActivityThread(9708): Application org.opencv.samples.tutorial3 is waiting for the debugger on port 8100...
05-31 23:41:45.983: I/System.out(9708): Sending WAIT chunk
05-31 23:41:45.983: I/dalvikvm(9708): Debugger is active
05-31 23:41:46.179: I/System.out(9708): Debugger has connected
05-31 23:41:46.179: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:46.382: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:46.585: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:46.788: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:46.983: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:47.186: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:47.389: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:47.585: I/System.out(9708): waiting for debugger to settle...
05-31 23:41:47.788: I/System.out(9708): debugger has settled (1463)
05-31 23:41:47.819: D/szipinf(9708): Initializing inflate state
05-31 23:41:47.866: I/Sample::Activity(9708): Instantiated new class org.opencv.samples.tutorial3.Sample3Native
05-31 23:41:48.909: D/dalvikvm(9708): threadid=1: still suspended after undo (sc=1 dc=1)
05-31 23:41:51.770: I/Sample::Activity(9708): onCreate
05-31 23:41:59.283: W/dalvikvm(9708): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/samples/tutorial3/Sample3View;
05-31 23:42:01.965: D/AndroidRuntime(9708): Shutting down VM
05-31 23:42:01.965: W/dalvikvm(9708): threadid=1: thread exiting with uncaught exception (group=0x40015560)
05-31 23:42:01.999: E/AndroidRuntime(9708): FATAL EXCEPTION: main
05-31 23:42:01.999: E/AndroidRuntime(9708): java.lang.ExceptionInInitializerError
05-31 23:42:01.999: E/AndroidRuntime(9708):     at org.opencv.samples.tutorial3.Sample3Native.onCreate(Sample3Native.java:21)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.app.ActivityThread.access$1500(ActivityThread.java:123)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.os.Looper.loop(Looper.java:130)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at android.app.ActivityThread.main(ActivityThread.java:3835)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at java.lang.reflect.Method.invokeNative(Native Method)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at java.lang.reflect.Method.invoke(Method.java:507)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at dalvik.system.NativeStart.main(Native Method)
05-31 23:42:01.999: E/AndroidRuntime(9708): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load native_sample: findLibrary returned null
05-31 23:42:01.999: E/AndroidRuntime(9708):     at java.lang.Runtime.loadLibrary(Runtime.java:429)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at java.lang.System.loadLibrary(System.java:554)
05-31 23:42:01.999: E/AndroidRuntime(9708):     at org.opencv.samples.tutorial3.Sample3View.<clinit>(Sample3View.java:48)
05-31 23:42:01.999: E/AndroidRuntime(9708):     ... 14 more

我觉得解决方案同样的问题但没人不帮我:

  1. Native OpenCV Samples for Android throw UnsatisfiedLinkError?
  2. java lang .UnsatisfiedLinkError:?! 无法加载opencv_java: 返回null findLibrary
  3. Major OpenCV Windows的Android Installing和Running Issues ( 无答案)?!

另外我还测试了它在不同的设备和Android API版本。

我的系统配置:

astor@astor-K42Jv:~$ uname -a
Linux astor-K42Jv 3.2.0-24-generic-pae #39-Ubuntu SMP Mon May 21 18:54:21 UTC 2012 i686 i686 i386 GNU/Linux

4 晚上的我已经尝试过修复此问题( 这是我的空闲时间= = = = = ),但无运气。 我很需要这种方式,所以任何帮助的论文将被赞赏。


Update : 我试验此示例在Windows 7 ( 64 ),但是结果是一样的。

似乎这是OpenCV bug 。


Update : Build日志:

astor@astor-K42Jv:/opt/eclipse-android/workspace/OpenCV-2.4.0-samples/tutorial-3-native$ ndk-build 
Install        : libnative_camera_r2.2.0.so => libs/armeabi-v7a/libnative_camera_r2.2.0.so
Install        : libnative_camera_r2.3.3.so => libs/armeabi-v7a/libnative_camera_r2.3.3.so
Install        : libnative_camera_r3.0.1.so => libs/armeabi-v7a/libnative_camera_r3.0.1.so
Install        : libnative_camera_r4.0.0.so => libs/armeabi-v7a/libnative_camera_r4.0.0.so
Install        : libnative_camera_r4.0.3.so => libs/armeabi-v7a/libnative_camera_r4.0.3.so
Install        : libnative_sample.so => libs/armeabi-v7a/libnative_sample.so
时间:原作者:4个回答

0 0

whoohoo !

我终于找到自己一个人解决此问题 !

我决定要调试的行:

System.loadLibrary("native_sample");

为此我下载android源代码从Android SDK然后附着的源文件夹 ( /opt/android sdk linux/sources/android 15 ) 到我的项目。 在此我发现错误为:

Cannot load library: link_image[1936]:    37 could not load needed library 'libopencv_java.so' for 'libhello-jni.so' (load_library[1091]: Library 'libopencv_java.so' not found)

这真正库不在 lib目录下。 我不知道为什么但是 ndk-build忽略了它。 所以我决定将其复制和负载manualy 。 为此我复制 libopencv_java.sofROM /opt/OpenCV-2.4.0/libs/armeabi-v7a以及编辑Java代码:

static {
    System.loadLibrary("opencv_java"); //load opencv_java lib
    System.loadLibrary("native_sample");
}

实际上类似的问题是:

  1. Can不能加载中OpenCV库necessitas?
  2. Android OpenCV :? 找dlopen照相机包装库

从第二个解决方案我发现我能使用 dlopen加载数据库,但是我还没有尝试过。

所以我将编写简单的bash脚本,给自己( just copy ) 就能做到了

这要归功于。

原作者:
0 0

你的较高级别比实际的问题。 请参见 " 入门NDK ",当你运行

    cd <project>
    <ndk>/ndk-build

。。。 气象预报怎么说来着? ( 记住要用Cygwin窗口而不是dos提示符) 。

原作者:
0 0

而不是加载原生库作为

static{
    System.loadLibrary("YOUR_LIBRARY");
}

opencv后加载你的库管理器中连接" onManagerConnected " 方法在你" baseloadercallback " 。 下面是我的代码段为我工作

public void onManagerConnected(int status) {
                switch(status){
                case LoaderCallbackInterface.SUCCESS:
                    Toast.makeText(getApplicationContext(), "manager connected", Toast.LENGTH_LONG).show();
                    System.loadLibrary("MYNATIVELIB");
                    break;
                default:
                    super.onManagerConnected(status);
                    break;
                }
            }
原作者:
...