如何使用CMake在Android上导入带有contrib的openCV?
我尝试在Android上使用contrib导入openCV。我引用了这个网站: 我无法使用contrib for Android构建opencv,因此我使用contrib sdk下载了opencv。我导入了模块,设置了依赖项,并编写了CMakeLists和build.gradle 这是我的CmakeList和build.gradle CMakeLists.txt如何使用CMake在Android上导入带有contrib的openCV?,android,opencv,cmake,opencv-contrib,Android,Opencv,Cmake,Opencv Contrib,我尝试在Android上使用contrib导入openCV。我引用了这个网站: 我无法使用contrib for Android构建opencv,因此我使用contrib sdk下载了opencv。我导入了模块,设置了依赖项,并编写了CMakeLists和build.gradle 这是我的CmakeList和build.gradle CMakeLists.txt # For more information about using CMake with Android Studio, read
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
set(pathOPENCV E:/opencv/opencv3-android-sdk-with-contrib-master/OpenCV-android-sdk)
set(pathPROJECT C:/Users/sms28/Downloads/artoolkit-android-studio-example- master/MyApplication7)
set(pathLIBOPENCV_JAVA C:/Users/sms28/Downloads/artoolkit-android-studio-example- master/MyApplication7/app/src/main/JniLibs/${ANDROID_ABI}/libopencv_java3.so)
set(CMAKE_VERBOSE_MAKEFILE on)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
include_directories(${pathOPENCV}/sdk/native/jni/include)
# 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 them for you.
# Gradle automatically packages shared libraries with your APK.
add_library(libopencv_java3 SHARED IMPORTED )
set_target_properties(libopencv_java3 PROPERTIES
IMPORTED_LOCATION "${pathLIBOPENCV_JAVA}")
add_library( # Sets the name of the library.
xfeatures2d
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/xfeatures2d_init.cpp
src/main/cpp/sift.cpp
src/main/cpp/surf.cpp
src/main/cpp/freak.cpp )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries 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 this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
xfeatures2d android log libopencv_java3
# Links the target library to the log library
# included in the NDK.
${log-lib} )
build.gradle(应用程序)
我建立了它,但我有错误:
欢迎使用堆栈溢出!在这里,我们希望错误消息以文本形式出现在问题帖子中,而不是以图像形式链接。请输入问题,并在其中插入错误的文本表示。您可以使用与代码相同的方式格式化生成日志。此外,似乎您添加了gradle脚本而不是
CMakeLists.txt
内容。OMGI没有注意到我的问题是狗屎,我修正了我的问题:)你仍然没有修正错误消息是文本,而不是链接图像。。。在任何地方,你尝试使用OpenCV两周都是很奇怪的,而且不在谷歌上搜索任何使用OpenCV的例子,例如,我成功地在android上使用了OpenCV。我就是不能用contrib打开CV。。。
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.sms28.myapplication"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11", "-frtti", "-fexceptions"
abiFilters 'x86', 'x86_64','armeabi-v7a', 'arm64-v8a'
}
}
}
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 {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':openCVLibrary340dev')
}