OpenCV Android - cannot solve the corresponding JNI function

I am trying to configure Android Studio using Opencv following the guide here: https://www.youtube.com/watch?v=OTw_GIQNbD8

I can get the result obtained by the person giving the tutorial, but trying to actually use some of the Opencv functions, I ran into some problems.

I can download the Opencv library, but trying to use some of the native functions, such as "Imgcodecs.imread", I get the error: ".lang.UnsatisfiedLinkError: for long org.opencv.imgcodecs.Imgcodecs, the implementation of .imread_1 (java. lang.String) "

I believe that I traced the problem to the following:

[! [enter image description here] [1]] [1]

It seems that Android Studio cannot detect native C ++ code, which I assume should be found from the jniLibs folder that I now have in app / src / main?

I tried updating Android Studio to the latest stable build, and I fixed the file paths for my Android SDK and NDK as having a space, apparently, could affect the operation of my own code. The problem still persists.

I have been trying to fix this in the last 4 hours, any help would be greatly appreciated!

+4
source share
2 answers

: , , Opencv Android SIFT/SURF - https://www.youtube.com/watch?v=cLK9CjQ-pNI

, . , , , , .

, Android SDK NDK. Android Studio , .

, *.so, /YOUR _PROJECT_ROOT/libs (, , libs). , , /src/main/jniLibs, .

openCVLibrary300, File- > New- > Import Module, - . \OpenCV-android-sdk\sdk\java

, build.gradle , min max sdk ..

, - http://pastebin.com/2zzU5B9G

, , Opencv. Imgcodecs.imread(), ++, ".lang.UnsatisfiedLinkError: , long org.opencv.imgcodecs.Imgcodecs.imread_1 (java.lang.String)" error.

enter image description here

enter image description here

enter image description here

+2

, , ndk Android Studio, . , , , .

, , , Android Studio - , Java - " ...". , , , .

(++, C) , .a .so src/main/jniLibs, gradle. .

src/main/jni, make jni. gradle .

opencv, (), :

:

make (, sdk make ):

Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include /home/ng/Desktop/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk

LOCAL_SRC_FILES  := DetectionBasedTracker_jni.cpp
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_LDLIBS     += -llog -ldl

LOCAL_MODULE     := detection_based_tracker

include $(BUILD_SHARED_LIBRARY)

Application.mk:

    APP_STL := gnustl_static
    APP_CPPFLAGS := -frtti -fexceptions
    APP_ABI := armeabi-v7a armeabi
    APP_PLATFORM := android-19

gradle.build :

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "org.opencv.samples.facedetect"
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    sourceSets.main.jni.srcDirs = []

    task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
       // ndkDir = project.plugins.findPlugin('com.android.application').getNdkFolder()
        commandLine "$ndkDir/ndk-build",
                'NDK_PROJECT_PATH=build/intermediates/ndk',
                'NDK_LIBS_OUT=src/main/jniLibs',
                'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
                'NDK_APPLICATION_MK=src/main/jni/Application.mk'
    }

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile project(':openCVLibrary300')
}

gradle . .so jniLibs. . , .

+3

Source: https://habr.com/ru/post/1613982/


All Articles