opencv android3.4.2环境搭建

环境:
1.mac os
2.android studio 3.1.3
3.opencv-3.4.2-android-sdk.zip
下载地址:

https://sourceforge.net/projects/opencvlibrary/files/opencv-android/

1.新建android项目

注意:选择Include C++ support

这里写图片描述

2.导入openCVLibrary342

导入opencv java依赖库

File -> New -> Import Module

这里写图片描述

3.导入openCV so库和静态库

将OpenCV-android-sdk-> sdk -> native 目录下
libs和staticlibs目录中的文件拷贝到android libs目录中

这里写图片描述

导入到android libs中

这里写图片描述

4.添加依赖

选择 app模块 右键 Project Structure

这里写图片描述

app/build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "cn.xylink.ocr.image"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++14 -frtti -fexceptions"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }

    packagingOptions{
        doNotStrip '*/mips/*.so'
        doNotStrip '*/mips64/*.so'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation project(':openCVLibrary342')
}

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: '**/*')
    into 'lib/'
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn(nativeLibsToJar)
}

buildscript {

    repositories {
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
//        jcenter()
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
//        jcenter()
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        google()
    }
}

build.gradle

buildscript {

    repositories {
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
//        jcenter()
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'

    }
}

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        google()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

local.properties

## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Aug 28 12:03:32 CST 2018
ndk.dir=/Users/hecj/profile/android-sdk-macosx/ndk-bundle
sdk.dir=/Users/hecj/profile/android-sdk-macosx
5.加载opencv lib

在Activity onResume中初始化

   @Override
    protected void onResume() {
        super.onResume();
        if (!OpenCVLoader.initDebug()){
        }
    }

注:此方法无需在额外安卓opencv Mannager apk了

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值