简体   繁体   English

Android版OpenCV-无法加载库

[英]OpenCV for Android - Cannot Load Library

I have been trying for hours to try to get either the OpenCV Manager application on Samsung Galaxy S5 to work or a static import of the opencv library and neither have worked. 我已经尝试了几个小时,试图使Samsung Galaxy S5上的OpenCV Manager应用程序正常工作,或者静态导入opencv库,但都没有工作。 I am using OpenCv 2.4.11. 我正在使用OpenCv 2.4.11。

For the static import I get the following error: 对于静态导入,我得到以下错误:

    04-18 20:49:08.591 15911-15911/com.example.jsupp.myapplication D/OpenCV/StaticHelper: Trying to get library list
04-18 20:49:08.601 15911-15911/com.example.jsupp.myapplication E/OpenCV/StaticHelper: OpenCV error: Cannot load info library for OpenCV
04-18 20:49:08.601 15911-15911/com.example.jsupp.myapplication D/OpenCV/StaticHelper: Library list: ""
04-18 20:49:08.601 15911-15911/com.example.jsupp.myapplication D/OpenCV/StaticHelper: First attempt to load libs
04-18 20:49:08.601 15911-15911/com.example.jsupp.myapplication D/OpenCV/StaticHelper: Trying to init OpenCV libs
04-18 20:49:08.601 15911-15911/com.example.jsupp.myapplication D/OpenCV/StaticHelper: Trying to load library opencv_java
04-18 20:49:08.601 15911-15911/com.example.jsupp.myapplication D/OpenCV/StaticHelper: Cannot load library "opencv_java"
04-18 20:49:08.601 15911-15911/com.example.jsupp.myapplication W/System.err: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.jsupp.myapplication-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libopencv_java.so"
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at java.lang.Runtime.loadLibrary(Runtime.java:366)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at java.lang.System.loadLibrary(System.java:989)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at org.opencv.android.StaticHelper.loadLibrary(StaticHelper.java:64)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at org.opencv.android.StaticHelper.initOpenCVLibs(StaticHelper.java:95)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at org.opencv.android.StaticHelper.initOpenCV(StaticHelper.java:39)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at org.opencv.android.OpenCVLoader.initDebug(OpenCVLoader.java:66)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at com.example.jsupp.myapplication.CalcMatches.<clinit>(CalcMatches.java:55)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at java.lang.reflect.Constructor.newInstance(Native Method)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at java.lang.Class.newInstance(Class.java:1650)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2505)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at android.app.ActivityThread.access$900(ActivityThread.java:172)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at android.os.Looper.loop(Looper.java:145)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5832)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
04-18 20:49:08.611 15911-15911/com.example.jsupp.myapplication D/OpenCV/StaticHelper: First attempt to load libs fails
04-18 20:49:08.691 15911-15911/com.example.jsupp.myapplication V/BitmapFactory: DecodeImagePath(decodeResourceStream3) : res/drawable-xhdpi-v4/ic_dialog_email.png
04-18 20:49:08.731 15911-15911/com.example.jsupp.myapplication V/BitmapFactory: DecodeImagePath(decodeResourceStream3) : res/drawable-xxhdpi-v4/abc_ic_ab_back_mtrl_am_alpha.png
04-18 20:49:08.751 15911-15911/com.example.jsupp.myapplication I/art: Alloc sticky concurrent mark sweep GC freed 2055(202KB) AllocSpace objects, 0(0B) LOS objects, 9% free, 76MB/84MB, paused 273us total 5.724ms
04-18 20:49:08.781 15911-15911/com.example.jsupp.myapplication I/art: Alloc partial concurrent mark sweep GC freed 309(25KB) AllocSpace objects, 2(60MB) LOS objects, 50% free, 15MB/31MB, paused 414us total 32.850ms
04-18 20:49:08.991 15911-15911/com.example.jsupp.myapplication E/art: No implementation found for long org.opencv.core.Mat.n_Mat(int, int, int) (tried Java_org_opencv_core_Mat_n_1Mat and Java_org_opencv_core_Mat_n_1Mat__III)

For the static implementation I simply used the openCV.initDebug method: 对于静态实现,我只使用了openCV.initDebug方法:

static {
        if (!OpenCVLoader.initDebug()) {
            // Handle initialization error
        }
    }

And I copied the Libs folders over but Android Studio does not seem to be able to find the library or include the libs folder in the application on the phone. 我复制了Libs文件夹,但Android Studio似乎无法在手机上的应用程序中找到该库或包含libs文件夹。

I have also tried to use the openCV manager application by following this tutorial: http://docs.opencv.org/2.4/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#application-development-with-static-initialization which does not return anything to indicate that the initialization has worked. 我还尝试通过遵循本教程来使用openCV管理器应用程序: http : //docs.opencv.org/2.4/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#application-development-with-static-initialization不返回任何内容以表明初始化已起作用。

What am I doing wrong? 我究竟做错了什么? Any help would be appreciated! 任何帮助,将不胜感激!

I figured out the issue it was basically just a matter of changing the location of some lines of code. 我发现这个问题基本上只是更改某些代码行的位置的问题。 I was executing a line of code: Mat testMat = new Mat(); 我正在执行一行代码: Mat testMat = new Mat(); in the onCreate method therefore not allowing the application to reach the OpenCV initialization method. 因此在onCreate方法中不允许应用程序使用OpenCV初始化方法。 This is a link to the page that helped me find the solution: 这是到帮助我找到解决方案的页面的链接:

UnsatisfiedLinkError: n_Mat while using opencv2.4.3 with android 4.0 UnsatisfiedLinkError:在Android 4.0上使用opencv2.4.3时使用n_Mat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM