我正在创建一个使用opencv C ++代码的项目。到目前为止,我只能找到托管在maven central中的java可执行文件: -
http://mvnrepository.com/artifact/nu.pattern/opencv/2.4.9-4
所以我在我的系统上安装了opencv并开始在我的项目中使用它。为了使用opencv头文件编译我的项目,我在build.gradle脚本中引入了以下内容: -
// C++ specific build configurations
// Acquiring environment variables
def opencvhome = System.getenv("OPENCV_HOME")
def opencvinclude = opencvhome + "\\include"
model {
components {
main(NativeLibrarySpec) {
sources {
cpp {
source {
srcDirs "src/main/cpp"
include "**/*.cpp"
}
exportedHeaders {
srcDirs "src/main/include", opencvinclude
}
}
}
}
}
}
这是为了包含必要的标题。注意opencvinclude部分被选为环境变量,我在运行gradle构建之前将其设置为安装位置。
现在我的问题是如何添加opencv的其他链接依赖项?
https://docs.gradle.org/current/userguide/nativeBinaries.html
我查阅了上述文件。它仅涵盖本身是gradle项目的依赖项。但opencv C ++不是一个gradle项目。有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
请参阅build.gradle的摘录,该摘录配置了与opencv库的静态链接
apply plugin: 'com.android.model.application'
model {
compileOptions.with {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
android {
compileSdkVersion = 22
buildToolsVersion = "22.0.1"
defaultConfig.with {
applicationId = "com.example.oleg.myapplication"
minSdkVersion.apiLevel = 18
targetSdkVersion.apiLevel = 22
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}
}
android.ndk {
moduleName = "fastcvUtils"
//abiFilters += ["armeabi", "armeabi-v7a", "x86"]
abiFilters += "armeabi-v7a"
// Link with static OpenCV libraries: the order is important!
// The following order taken from OpenCV.mk
def opencv_modules = ["shape", "stitching", "objdetect", "superres", "videostab", "calib3d", "features2d", "highgui", "videoio", "imgcodecs", "video", "photo", "ml", "imgproc", "flann", "core", "hal"]
ldLibs += ["log","stdc++","dl", "z"]
abiFilters.each { targetAbi ->
println targetAbi
opencv_modules.each{ module ->
ldLibs += file(projectDir).absolutePath + "/src/main/jniLibs/" + targetAbi + "/libopencv_" + module + ".a"
}
}
cppFlags += "-Werror"
cppFlags += "--debug"
cppFlags += "-frtti"
cppFlags += "-fexceptions"
cppFlags += "-I/Users/Oleg/Downloads/OpenCV-android-sdk/sdk/native/jni/include"
ldLibs += file(projectDir).absolutePath+"/src/main/jniLibs/armeabi-v7a/libtbb.a"
stl = "gnustl_static"
}
android.buildTypes {
release {
isMinifyEnabled = false
proguardFiles += file('proguard-android.pro')
isJniDebuggable = true
isDebuggable = true
}
debug {
isJniDebuggable = true
isDebuggable = true
}
}
android.productFlavors {
create("arm") {
ndk.with {
abiFilters += "armeabi"
println "*** building for arm"
}
}
create("armv7") {
ndk.with {
abiFilters += "armeabi-v7a"
println "*** building for armv7"
}
}
create("x86") {
ndk.with {
abiFilters += "x86"
println "*** building for x86"
}
}
}
}
它假设.a库从OpenCV SDK复制到jniLibs文件夹