我正在尝试在我的应用中包含筛选功能检测器来识别捕获的图像。由于我的模型是使用筛选描述符进行训练的,因此我别无选择,只能将其用于检索目的。我按照Gouhui Wang's和Kornel的教程来构建我的libopencv_java
,libnonfree.so
文件。我将它们添加到我的testProject \ app \ src \ main \ jniLibs文件夹中。我添加了#include<opencv2/nonfree/nonfree.hpp>
。当我向代码添加SiftFeatureDetector detector
时,它显示错误。我见过的所有例子都谈到在eclipse中包含这个库而不是android studio。任何人都可以指出我在这里正确的方向。我包括我的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} )
&#13;
这是我在构建项目时遇到的错误
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.
&#13;
这是我的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')
}
&#13;
感谢您的帮助