无法在 Android 中加载库 “opencv_java4″。

huangapple go评论84阅读模式
英文:

Cannot load library "opencv_java4" in android

问题

以下是翻译好的部分:

Error (Console)
当调用该函数时显示的错误:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.logicaldp.fingerprintrecog, PID: 13300
java.lang.NullPointerException: Attempt to invoke virtual method 'int org.opencv.core.Mat.rows()' on a null object reference
at com.logicaldp.fingerprintrecog.ProcessActivity.showImage(ProcessActivity.java:283)
at com.logicaldp.fingerprintrecog.ProcessActivity.buttonFilter_OnClick(ProcessActivity.java:184)
at com.logicaldp.fingerprintrecog.ProcessActivity.access$600(ProcessActivity.java:36)
at com.logicaldp.fingerprintrecog.ProcessActivity$7.onClick(ProcessActivity.java:262)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Logcat
实际的错误有点隐蔽,所以我手动打印了它。请注意。

2020-04-02 20:26:03.012 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: First attempt to load libs
2020-04-02 20:26:03.012 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: Trying to init OpenCV libs
2020-04-02 20:26:03.012 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: Trying to load library opencv_java4
2020-04-02 20:26:03.012 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: Cannot load library "opencv_java4"
...
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.logicaldp.fingerprintrecog-C0x7aZ1B4lxWlz9OZO3RRA==/base.apk"]],nativeLibraryDirectories=[/data/app/com.logicaldp.fingerprintrecog-C0x7aZ1B4lxWlz9OZO3RRA==/lib/x86, /system/lib, /system/product/lib]]] couldn't find "libopencv_java4.so"
...
2020-04-02 20:26:03.170 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: First attempt to load libs fails
2020-04-02 20:26:03.170 14935-14935/com.logicaldp.fingerprintrecog D/ERROR: Unable to load OpenCV

ProcessActivity.java
这是主要内容,我之前使用了initAsync,但我读到它不再起作用,所以切换到initDebug,但仍然得到相同的错误。

@Override
public void onResume() {
    super.onResume();
    if (!OpenCVLoader.initDebug()) {
        Log.d("ERROR", "Unable to load OpenCV");
    } else {
        mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
    }
}

Build.gradle

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.logicaldp.fingerprintrecog"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs'] } }
    externalNativeBuild {
        ndkBuild {
            path file('../../../Downloads/OpenCV-android-sdk-2/sdk/native/jni/OpenCV.mk')
        }
    }
    sourceSets.main {
        jniLibs.srcDirs = ['libs']
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation project(path: ':OpenCV')
}
英文:

Trying to get android to work with opencv but getting this error. attaching the error log and relevant codes.

I have followed the opencv android tutorial for this to setup the project.

Error (Console)
This shows when called the function

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.logicaldp.fingerprintrecog, PID: 13300
java.lang.NullPointerException: Attempt to invoke virtual method 'int org.opencv.core.Mat.rows()'
on a null object reference
at com.logicaldp.fingerprintrecog.ProcessActivity.showImage(ProcessActivity.java:283)
at
com.logicaldp.fingerprintrecog.ProcessActivity.buttonFilter_OnClick(ProcessActivity.java:184)
at com.logicaldp.fingerprintrecog.ProcessActivity.access$600(ProcessActivity.java:36)
at com.logicaldp.fingerprintrecog.ProcessActivity$7.onClick(ProcessActivity.java:262)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Logcat
The actual error is a little hidden so I have printed it manually. Please take note.

2020-04-02 20:26:01.660 14935-14935/? I/ingerprintreco: Not late-enabling -Xcheck:jni (already on)
2020-04-02 20:26:01.686 14935-14935/? E/ingerprintreco: Unknown bits set in runtime_flags: 0x8000
2020-04-02 20:26:01.693 14935-14935/? W/ingerprintreco: Unexpected CPU variant for X86 using defaults: x86
2020-04-02 20:26:01.856 14935-14935/com.logicaldp.fingerprintrecog W/RenderThread: type=1400 audit(0.0:96): avc: denied { write } for name="property_service" dev="tmpfs" ino=9472 scontext=u:r:untrusted_app:s0:c152,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
2020-04-02 20:26:01.859 14935-14973/com.logicaldp.fingerprintrecog D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
2020-04-02 20:26:01.862 14935-14973/com.logicaldp.fingerprintrecog W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
2020-04-02 20:26:01.884 14935-14973/com.logicaldp.fingerprintrecog D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2020-04-02 20:26:01.885 14935-14973/com.logicaldp.fingerprintrecog D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2020-04-02 20:26:01.887 14935-14973/com.logicaldp.fingerprintrecog D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2020-04-02 20:26:01.933 14935-14970/com.logicaldp.fingerprintrecog D/HostConnection: HostConnection::get() New Host Connection established 0xe1b662d0, tid 14970
2020-04-02 20:26:01.934 14935-14970/com.logicaldp.fingerprintrecog D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0 
2020-04-02 20:26:01.945 14935-14970/com.logicaldp.fingerprintrecog W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2020-04-02 20:26:01.946 14935-14970/com.logicaldp.fingerprintrecog D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
2020-04-02 20:26:01.946 14935-14970/com.logicaldp.fingerprintrecog D/EGL_emulation: eglCreateContext: 0xe1b1a1e0: maj 3 min 0 rcv 3
2020-04-02 20:26:01.947 14935-14970/com.logicaldp.fingerprintrecog D/EGL_emulation: eglMakeCurrent: 0xe1b1a1e0: ver 3 0 (tinfo 0xe1b0f260)
2020-04-02 20:26:01.960 14935-14970/com.logicaldp.fingerprintrecog W/Gralloc3: mapper 3.x is not supported
2020-04-02 20:26:01.962 14935-14970/com.logicaldp.fingerprintrecog D/HostConnection: createUnique: call
2020-04-02 20:26:01.962 14935-14970/com.logicaldp.fingerprintrecog D/HostConnection: HostConnection::get() New Host Connection established 0xe1b66460, tid 14970
2020-04-02 20:26:01.962 14935-14970/com.logicaldp.fingerprintrecog D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0 
2020-04-02 20:26:01.963 14935-14970/com.logicaldp.fingerprintrecog D/eglCodecCommon: allocate: Ask for block of size 0x1000
2020-04-02 20:26:01.963 14935-14970/com.logicaldp.fingerprintrecog D/eglCodecCommon: allocate: ioctl allocate returned offset 0x3ffff2000 size 0x2000
2020-04-02 20:26:01.968 14935-14970/com.logicaldp.fingerprintrecog D/EGL_emulation: eglMakeCurrent: 0xe1b1a1e0: ver 3 0 (tinfo 0xe1b0f260)
2020-04-02 20:26:01.988 14935-14970/com.logicaldp.fingerprintrecog D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
2020-04-02 20:26:02.995 14935-14935/com.logicaldp.fingerprintrecog W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@a23770e
2020-04-02 20:26:03.011 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: Trying to get library list
2020-04-02 20:26:03.011 14935-14935/com.logicaldp.fingerprintrecog E/OpenCV/StaticHelper: OpenCV error: Cannot load info library for OpenCV
2020-04-02 20:26:03.012 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: Library list: ""
2020-04-02 20:26:03.012 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: First attempt to load libs
2020-04-02 20:26:03.012 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: Trying to init OpenCV libs
2020-04-02 20:26:03.012 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: Trying to load library opencv_java4
2020-04-02 20:26:03.012 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: Cannot load library "opencv_java4"
2020-04-02 20:26:03.012 14935-14935/com.logicaldp.fingerprintrecog W/System.err: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.logicaldp.fingerprintrecog-C0x7aZ1B4lxWlz9OZO3RRA==/base.apk"],nativeLibraryDirectories=[/data/app/com.logicaldp.fingerprintrecog-C0x7aZ1B4lxWlz9OZO3RRA==/lib/x86, /system/lib, /system/product/lib]]] couldn't find "libopencv_java4.so"
2020-04-02 20:26:03.013 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at java.lang.Runtime.loadLibrary0(Runtime.java:1067)
2020-04-02 20:26:03.013 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
2020-04-02 20:26:03.013 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at java.lang.System.loadLibrary(System.java:1667)
2020-04-02 20:26:03.013 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at org.opencv.android.StaticHelper.loadLibrary(StaticHelper.java:64)
2020-04-02 20:26:03.013 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at org.opencv.android.StaticHelper.initOpenCVLibs(StaticHelper.java:95)
2020-04-02 20:26:03.013 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at org.opencv.android.StaticHelper.initOpenCV(StaticHelper.java:39)
2020-04-02 20:26:03.014 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at org.opencv.android.OpenCVLoader.initDebug(OpenCVLoader.java:107)
2020-04-02 20:26:03.014 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at com.logicaldp.fingerprintrecog.ProcessActivity.<clinit>(ProcessActivity.java:41)
2020-04-02 20:26:03.014 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at java.lang.Class.newInstance(Native Method)
2020-04-02 20:26:03.014 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
2020-04-02 20:26:03.014 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
2020-04-02 20:26:03.014 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.Instrumentation.newActivity(Instrumentation.java:1243)
2020-04-02 20:26:03.014 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3182)
2020-04-02 20:26:03.014 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
2020-04-02 20:26:03.014 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
2020-04-02 20:26:03.015 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
2020-04-02 20:26:03.015 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
2020-04-02 20:26:03.015 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
2020-04-02 20:26:03.015 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:107)
2020-04-02 20:26:03.015 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.os.Looper.loop(Looper.java:214)
2020-04-02 20:26:03.015 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7356)
2020-04-02 20:26:03.015 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2020-04-02 20:26:03.015 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
2020-04-02 20:26:03.015 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
2020-04-02 20:26:03.016 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: First attempt to load libs fails
2020-04-02 20:26:03.168 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: Trying to get library list
2020-04-02 20:26:03.168 14935-14935/com.logicaldp.fingerprintrecog E/OpenCV/StaticHelper: OpenCV error: Cannot load info library for OpenCV
2020-04-02 20:26:03.168 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: Library list: ""
2020-04-02 20:26:03.168 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: First attempt to load libs
2020-04-02 20:26:03.168 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: Trying to init OpenCV libs
2020-04-02 20:26:03.168 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: Trying to load library opencv_java4
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: Cannot load library "opencv_java4"
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.logicaldp.fingerprintrecog-C0x7aZ1B4lxWlz9OZO3RRA==/base.apk"],nativeLibraryDirectories=[/data/app/com.logicaldp.fingerprintrecog-C0x7aZ1B4lxWlz9OZO3RRA==/lib/x86, /system/lib, /system/product/lib]]] couldn't find "libopencv_java4.so"
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at java.lang.Runtime.loadLibrary0(Runtime.java:1067)
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at java.lang.System.loadLibrary(System.java:1667)
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at org.opencv.android.StaticHelper.loadLibrary(StaticHelper.java:64)
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at org.opencv.android.StaticHelper.initOpenCVLibs(StaticHelper.java:95)
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at org.opencv.android.StaticHelper.initOpenCV(StaticHelper.java:39)
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at org.opencv.android.OpenCVLoader.initDebug(OpenCVLoader.java:107)
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at com.logicaldp.fingerprintrecog.ProcessActivity.onResume(ProcessActivity.java:1172)
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1446)
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.Activity.performResume(Activity.java:7939)
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4195)
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4237)
2020-04-02 20:26:03.169 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
2020-04-02 20:26:03.170 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
2020-04-02 20:26:03.170 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
2020-04-02 20:26:03.170 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
2020-04-02 20:26:03.170 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:107)
2020-04-02 20:26:03.170 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.os.Looper.loop(Looper.java:214)
2020-04-02 20:26:03.170 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7356)
2020-04-02 20:26:03.170 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2020-04-02 20:26:03.170 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
2020-04-02 20:26:03.170 14935-14935/com.logicaldp.fingerprintrecog W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
2020-04-02 20:26:03.170 14935-14935/com.logicaldp.fingerprintrecog D/OpenCV/StaticHelper: First attempt to load libs fails
2020-04-02 20:26:03.170 14935-14935/com.logicaldp.fingerprintrecog D/ERROR: Unable to load OpenCV

ProcessActivity.java
This is the main thing, I was using initAsync but I read that it doesn't work anymore so switched to initDebug but still getting the same error.

 @Override
public void onResume()
{
super.onResume();
//        if (!OpenCVLoader.initDebug()) {
//            Log.d("OpenCV", "Internal OpenCV library not found. Using OpenCV Manager for initialization");
//            OpenCVLoader.initAsync(OPENCV_VERSION_3_0_0, this, mLoaderCallback);
//        } else {
//            Log.d("OpenCV", "OpenCV library found inside package. Using it!");
//            mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
//        }
if (!OpenCVLoader.initDebug()) {
Log.d("ERROR", "Unable to load OpenCV");
} else {
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
}

Build.gradle

apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.logicaldp.fingerprintrecog"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs'] } }
externalNativeBuild {
ndkBuild {
path file('../../../Downloads/OpenCV-android-sdk-2/sdk/native/jni/OpenCV.mk')
}
}
sourceSets.main {
jniLibs.srcDirs = ['libs']
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(path: ':OpenCV')
}

答案1

得分: 3

试试这个,我重新将OpenCV作为模块导入,对我有效:

  • 文件 > 新建 > 导入模块(opencv所在的路径) 例如,Downloads\OpenCV-android-sdk\sdk
  • 文件 > 项目结构 > 依赖项 > 点击 app 模块 > 点击"+" 图标 > 选择 模块依赖项 > 点击新导入的模块(opencv-sdk
  • Opencv sdk 中,复制位于opencv文件夹所在位置的 libs 文件夹(例如,Downloads\OpenCV-android-sdk\sdk\native)
  • 将复制的 libs 文件夹粘贴到项目文件夹 app\src\main 中,并将其重命名为 jnilibs
  • 在加载opencv库并检查是否成功加载opencv的代码中添加以下内容(将其添加到oncreate中)
val ocvLoaded = OpenCVLoader.initDebug();
if (ocvLoaded) 
{ 
    Toast.makeText( this@MainActivity, "OpenCV已加载", Toast.LENGTH_SHORT ).show();
}
else 
{ 
    Toast.makeText( this@MainActivity, "无法加载OpenCV", Toast.LENGTH_SHORT ).show();
}
英文:

Try this, I reimported the opencv as module and it works for me:

  • File > New > Import Module (path where the opencv is located) e.g., Downloads\OpenCV-android-sdk\sdk
  • File > Project Structure > Dependencies > Click app module > click "+" icon > choose Module Dependency > click the newly imported module (opencv-sdk)
  • In Opencv sdk, copy the libs folder located where the opencv folder (e.g. Downloads\OpenCV-android-sdk\sdk\native)
  • paste the copied libs folder in the project folder app\src\main and rename it jnilibs
  • Add this code for loading the opencv library and checking if opencv is successfully loaded (add this in oncreate)
val ocvLoaded = OpenCVLoader.initDebug();
if (ocvLoaded) 
{ 
Toast.makeText( this@MainActivity, "OpenCV loaded", Toast.LENGTH_SHORT ).show();
}
else 
{ 
Toast.makeText( this@MainActivity, "Unable to load OpenCV", Toast.LENGTH_SHORT ).show();
}

答案2

得分: 1

我遇到了相同的问题,但尝试了不同的解决方案,都没有起作用
后来我通过以下方法解决了这个问题:

在你的项目中导入openCV模块时,
不要导入path/to/openCV/sdk/java
而是导入path/to/openCV/sdk/

英文:

I faced same issue but after trying different solutions, none of them worked
than I fixed the issue by:

while importing openCV module in your project
do not import path/to/openCV/sdk/java
but import path/to/openCV/sdk/

huangapple
  • 本文由 发表于 2020年4月4日 17:50:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/61026347.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定