Использование несвободных (OpenCV C++) библиотек в Android Studio

Я пытаюсь включить детектор функций просеивания в свое приложение для распознавания захваченного изображения. Поскольку моя модель обучается с использованием дескрипторов просеивания, у меня нет другого выбора, кроме как использовать их для целей поиска. Я следовал руководствам Гухуэй Ванга и Kornel для создания файлов libopencv_java, libnonfree.so. Я добавил их в папку testProject\app\src\main\jniLibs. Я добавил #include<opencv2/nonfree/nonfree.hpp>. Когда я добавляю SiftFeatureDetector detector в свой код, он показывает ошибку. Все примеры, которые я видел, говорят о включении этой библиотеки в eclipse, но не в студию Android. Может ли кто-нибудь указать мне в правильном направлении здесь. Я включаю свой cmakeList.txt

# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.

cmake_minimum_required(VERSION 3.4.1)

include_directories(C:/OpenCV-android-sdk/sdk/native/jni/include)
add_library( lib_opencv SHARED IMPORTED )
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java.so)

include_directories(C:/OpenCV-android-sdk/sdk/native/jni/include/opencv2/nonfree)
add_library( lib_nonfree SHARED IMPORTED )
set_target_properties(lib_nonfree
 PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libnonfree_java.so)



# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             # Associated headers in the same location as their source
             # file are automatically included.
             src/main/cpp/native-lib.cpp )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
                       native-lib
                       lib_opencv
                       lib_nonfree
                       app-glue
                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

Это ошибка, которую я получаю при создании проекта

Error:FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing 'C:\Users\HOME\AppData\Local\Android\Sdk\cmake\3.6.3155560\bin\cmake.exe' with arguments {--build C:\Users\HOME\AndroidStudioProjects\BequestProto\app\.externalNativeBuild\cmake\debug\mips --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
C:\Users\HOME\AndroidStudioProjects\BequestProto\app\src\main\cpp\native-lib.cpp:338:1: warning: control reaches end of non-void function [-Wreturn-type]
  }
  ^
  1 warning generated.
  [2/2] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\mips\libnative-lib.so
FAILED: cmd.exe /C "cd . && C:\Users\HOME\AppData\Local\Android\android-ndk-r13b\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe  -target mipsel-none-linux-android -gcc-toolchain C:/Users/HOME/AppData/Local/Android/android-ndk-r13b/toolchains/mipsel-linux-android-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/HOME/AppData/Local/Android/android-ndk-r13b/platforms/android-9/arch-mips -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mips32 -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mips32 -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -frtti -fexceptions -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info  -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\mips\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o  ../../../../src/main/jniLibs/mips/libopencv_java.so ../../../../src/main/jniLibs/mips/libnonfree_java.so -lapp-glue -llog -lm "C:/Users/HOME/AppData/Local/Android/android-ndk-r13b/sources/cxx-stl/gnu-libstdc++/4.9/libs/mips/libgnustl_static.a" && cd ."
C:/Users/HOME/AppData/Local/Android/android-ndk-r13b/toolchains/mipsel-linux-android-4.9/prebuilt/windows-x86_64/lib/gcc/mipsel-linux-android/4.9.x/../../../../mipsel-linux-android/bin\ld: cannot find -lapp-glue
  clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Вот мой build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    defaultConfig {
        applicationId "com.example.home.BequestProto"
        minSdkVersion 10
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {

            cmake{
                cppFlags "-frtti -fexceptions"
                abiFilters 'x86', 'armeabi-v7a', 'mips'
            }
        }

        ndk{

            abiFilters 'x86', 'armeabi-v7a', 'mips'
        }
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['src/main/jniLibs']
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }

    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
    compile project(':openCVLibrary2411')
    compile files('libs/commons-compress-1.12.jar')
}

Спасибо за помощь


person vamsidhar muthireddy    schedule 21.12.2016    source источник
comment
Я вижу, что это было очень давно. Вы когда-нибудь решали это. Я назначил вознаграждение за аналогичный вопрос: stackoverflow.com/questions/44079701/   -  person Dale    schedule 19.09.2019