Android Studio配置OpenCV(无需安装OpenCV Manager)

Andrioid Stduio 配置OpenCv特别简单:

一、在Android Studio中import module,导入我们需要的OpenCV Library。一直next就行!

2.在openCVLibrary module中修改相关参数。修改参数部分是第二幅图,数字改成和app Module一样就行。然后Sync now!

3、接下来讲OpenCVLibrary中的libs下的东西全部复制到app下的libs中。接着在build.gradle中加入代码(粗体字)!

dependencies {

compile fileTree(include: ['*.jar'],dir:'libs')

compile fileTree(include:'native-libs.jar',dir:"$buildDir/native-libs")

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {

excludegroup:'com.android.support',module:'support-annotations'

})

compile project(':openCVLibrary310')

compile'com.android.support:appcompat-v7:26.+'

compile'com.android.support.constraint:constraint-layout:1.0.2'

testCompile'junit:junit:4.12'

}

task nativeLibsTojar(type: Jar,description:'create a jar archive of the native libs') {

destinationDir file("$buildDir/native-libs")

baseName'native-libs'

from fileTree(dir:'libs',include:'**/*.so')

into'lib/'

}

tasks.withType(org.gradle.api.tasks.compile.JavaCompile) {

compileTask -> compileTask.dependsOn(nativeLibsTojar)

}

4、接下来我们就只需要初始化OpenCVLibrary即可!

@Override

protected voidonCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

initLoadOpenCVLibs();

}

private voidinitLoadOpenCVLibs() {

booleansuccess= OpenCVLoader.initDebug();

if(success){

Log.d(TAG,"Load Library successfully......");

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容