gpt4 book ai didi

android - Android 上的 OpenCV : Couldn't load opencv_java from loader - do I have to compile with NDK? 我错过了什么吗?

转载 作者:太空狗 更新时间:2023-10-29 16:16:05 24 4
gpt4 key购买 nike

我觉得我在这里错过了一些明显的东西。我正在尝试让 OpenCV 在 Android 上运行。我想使用静态初始化方法,所以我将适当的 native 库文件从 OpenCV SDK 复制到我的 Android Studio 项目中的 app/libs/armeabi-v7a 文件夹中。我知道谷歌眼镜(我正在开发的)使用这种架构——无论如何,我还有/lib/armeabi 文件夹以防万一。

我在 StackOverflow 上搜索这里,当然 answers.opencv.org 已关闭。我找到的答案并没有解决问题。据我了解,我:

  • 为 Android 安装 NDK
  • 下载并解压缩 OpenCV SDK
  • 将其作为Android库导入并添加为模块依赖
  • 将库文件复制到/libs/armeabi-v7a(在我的 Android Studio 项目中)
  • 使用以下代码,库应该正确加载:

    if (!OpenCVLoader.initDebug()) {
    Log.e("OpenCV","Unable to load OpenCV");
    } else {
    Log.e("OpenCV","OpenCV has loaded!");
    }

但是,我得到这个错误:

12-16 08:46:08.047    1838-1838/com.company.opencvsdktest D/OpenCV/StaticHelper﹕ Trying to get library list
12-16 08:46:08.047 1838-1838/com.company.opencvsdktest E/OpenCV/StaticHelper﹕ OpenCV error: Cannot load info library for OpenCV
12-16 08:46:08.047 1838-1838/com.company.opencvsdktest D/OpenCV/StaticHelper﹕ Library list: ""
12-16 08:46:08.047 1838-1838/com.company.opencvsdktest D/OpenCV/StaticHelper﹕ First attempt to load libs
12-16 08:46:08.047 1838-1838/com.company.opencvsdktest D/OpenCV/StaticHelper﹕ Trying to init OpenCV libs
12-16 08:46:08.047 1838-1838/com.company.opencvsdktest D/OpenCV/StaticHelper﹕ Trying to load library opencv_java
12-16 08:46:08.047 1838-1838/com.company.opencvsdktest D/OpenCV/StaticHelper﹕ Cannot load library "opencv_java"
12-16 08:46:08.047 1838-1838/com.company.opencvsdktest W/System.err﹕ java.lang.UnsatisfiedLinkError: Couldn't load opencv_java from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.company.opencvsdktest-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.company.opencvsdktest-1, /vendor/lib, /system/lib]]]: findLibrary returned null
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at java.lang.Runtime.loadLibrary(Runtime.java:358)
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at java.lang.System.loadLibrary(System.java:529)
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at org.opencv.android.StaticHelper.loadLibrary(StaticHelper.java:64)
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at org.opencv.android.StaticHelper.initOpenCVLibs(StaticHelper.java:95)
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at org.opencv.android.StaticHelper.initOpenCV(StaticHelper.java:39)
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at org.opencv.android.OpenCVLoader.initDebug(OpenCVLoader.java:62)
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at com.company.opencvsdktest.MainActivity.onResume(MainActivity.java:93)
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1194)
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at android.app.Activity.performResume(Activity.java:5315)
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2804)
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2843)
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2278)
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at android.app.ActivityThread.access$800(ActivityThread.java:138)
12-16 08:46:08.055 1838-1838/com.company.opencvsdktest W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1236)
12-16 08:46:08.063 1838-1838/com.company.opencvsdktest W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
12-16 08:46:08.063 1838-1838/com.company.opencvsdktest W/System.err﹕ at android.os.Looper.loop(Looper.java:149)
12-16 08:46:08.063 1838-1838/com.company.opencvsdktest W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5045)
12-16 08:46:08.063 1838-1838/com.company.opencvsdktest W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
12-16 08:46:08.063 1838-1838/com.company.opencvsdktest W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
12-16 08:46:08.063 1838-1838/com.company.opencvsdktest W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-16 08:46:08.063 1838-1838/com.company.opencvsdktest W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
12-16 08:46:08.063 1838-1838/com.company.opencvsdktest W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
12-16 08:46:08.063 1838-1838/com.company.opencvsdktest D/OpenCV/StaticHelper﹕ First attempt to load libs fails
12-16 08:46:08.063 1838-1838/com.company.opencvsdktest E/OpenCV﹕ Unable to load OpenCV
12-16 08:46:08.211 1838-1838/com.company.opencvsdktest D/OpenGLRenderer﹕ Enabling debug mode 0

我必须对 SDK 做任何额外的事情吗?我需要先编译什么吗?还是应该自动工作?如果我安装了 NDK,除了此处提到的步骤之外,我不必任何事情:http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#application-development-with-static-initialization正确的?

编辑:我还尝试了 libs 文件夹的不同位置,例如在项目根目录和 openCVLibrary 文件夹中。都没有用。

编辑 2:使用 Manager APK 工作正常。但是对于 Glass,这并不是真正的解决方案,因为无法访问 Play 商店!

最佳答案

要解决您的问题,请尝试以下步骤:

  1. 查看 Application.mk 并检查 APP_ABI 是否配置正确。 OpenCV 示例使用 armeabi-v7a 作为默认 objective-c pu 架构。但就我而言,我的应用是针对 arm64-v8a 设备部署的。因此要尝试:

    APP_ABI := all

    ... 以确保 jni-libs 也将为您的设备构建。

  2. build.gradle 文件中将 'libs' 文件夹设置为新的 jniLibs(jni *.so 的库)

_

 sourceSets{
main {
jni.srcDirs =[]
jniLibs.srcDirs = ['src/main/libs'] # to change to your project structure
}
}

关于android - Android 上的 OpenCV : Couldn't load opencv_java from loader - do I have to compile with NDK? 我错过了什么吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27506341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com