androidstudio+opencv

This will be my first blog in English.

Now , Let's begin.

Step 1:download the resources 

  download  OpenCV-2.4.10-android-sdk.zip from http://opencv.org/downloads.html

Step 2:copy the OpenCV SDK into your project

  decompress the package , then , cp OpenCV-->sdk-->java   to  Your_Project ---> libraries(created by ourselves)

  rename the directory , mv java ---> opencv

 

Setp 3: create build.gradle file in opencv dirctory, then setup it

  In this freshly mkdir folder add a typical build.gradle file; setup it like this:

apply plugin: 'android-library'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }


    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
            aidl.srcDirs = ['src']
        }
    }
}

  when you create or setting up build.gradle , the android studio will promote to synchronous。

  if not promoted to syn , then manually add "

    include ':app', ':opencv'    //:app is the original

    project(':opencv').projectDir = new File('libraries/opencv')

    " 

  then syn by manually.

 

Step 4:Set up "Open Module settings"

  click "+", add module dependency, selcet ":opencv" , click "apply" button

  

 

Step 5: copy OpenCV binaries into your project

  OpenCV-2.?.?-android-sdk -> sdk -> native -> libs -> armeabi-v7a

  to

  out of OpenCV-2... -> lib --> armeabi-v7a  //lib is a temporary folder. libraries is created before

  decompress lib folder

  zip -r libopencl-v7a.jar lib   //压缩后名字改成 *.jar

  then copy

  mv libopencl-v7a.jar  Project Root -> Your Project -> libraries (created before)

 

Step 6 : check it

  add "if (!OpenCVLoader.initDebug()) {} ", and it will promote you to add "import org.opencv.android.OpenCVLoader;"

  

  rebuild the project . if it is ok, everything is ok.

 

 

Related links:

http://stackoverflow.com/questions/17767557/how-to-use-opencv-in-android-studio-using-gradle-build-tool  //It's best, two solution , each has advantages and disadvantages

http://hujiaweibujidao.github.io/blog/2014/10/22/android-ndk-and-opencv-development-with-android-studio/  //This is also good blog about how to install android NDK and OpenCV 。 The author of this blog is a student in Tsinghua University.

转载于:https://www.cnblogs.com/zhongyuan/p/4196206.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值