GithubHelp home page GithubHelp logo

sea5241 / face_detection Goto Github PK

View Code? Open in Web Editor NEW

This project forked from weichaoio/face_detection

0.0 2.0 0.0 164.88 MB

Android Studio(AS) 导入 OpenCV 的 face-detection(人脸识别)工程

CMake 0.09% Java 99.04% C++ 0.87%

face_detection's Introduction

[toc]


#

AS 导入 OpenCV 工程之 face-detection


#TODO

  • []

#Reference


#准备工作

(见 【Eclipse 导入 OpenCV 工程之 face-detection】


#导入工程

##打开 AS 并创建新工程

##从 Android 视图转为 Project 视图

##添加 NDK 支持

File -> Project Structure...

##导入 lib 模块

File -> New -> Import Module...

###非正常情况

####target 未找到

#####Question

Error:Failed to find target with hash string 'android-*' in: *

#####Why

未安装 Android 14 的 SDK。

#####Answer

换成已安装的版本。

源代码:

修改为:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 25
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

重新编译。

##添加 app 模块对 lib 模块的引用

File -> Project Structure...

选择 lib。

##添加 app 模块的 JNI lib

###新建 jniLibs 目录

右键 main -> New -> Directory

###复制 JNI lib 文件到 jniLibs

JNI lib 文件所在目录:D:\OpenCV-3.2.0-android-sdk\sdk\native\libs

###配置 JNI lib

修改后,代码为:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "io.weichao.face_detection"
        minSdkVersion 18
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11 -frtti -fexceptions"
                abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['D:\\android_studio_workspace\\Face_Detection\\app\\src\\main\\jniLibs']
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    testCompile 'junit:junit:4.12'
    compile project(':openCVLibrary320')
}

###重新编译

##复制 face-detection 工程的资源文件到 app 模块

资源文件所在目录:D:\OpenCV-3.2.0-android-sdk\samples\face-detection\res

##删除 app 模块 java 文件,复制 face-detection 工程的源代码文件到 app 模块

源代码文件所在目录:D:\OpenCV-3.2.0-android-sdk\samples\face-detection\src

##替换 AndroidManifest.xml

AndroidManifest.xml 文件路径:D:\OpenCV-3.2.0-android-sdk\samples\face-detection\AndroidManifest.xml

##删除 app 模块 C/C++ 文件,复制 face-detection 工程的 C/C++ 文件到 app 模块

C/C++ 文件所在目录:D:\OpenCV-3.2.0-android-sdk\samples\face-detection\jni

##修改 CMakeLists.txt

#CMake版本信息
cmake_minimum_required(VERSION 3.4.1)

# 支持-std=gnu++11
set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

# 工程路径
set(pathToProject D:/android_studio_workspace/Face_Detection)
# OpenCV-android-sdk路径
set(pathToOpenCv D:/OpenCV-3.2.0-android-sdk)

# 配置加载native依赖
include_directories(${pathToOpenCv}/sdk/native/jni/include)

# 添加待编译的cpp文件
add_library(detection_based_tracker SHARED ${pathToProject}/app/src/main/cpp/DetectionBasedTracker_jni.h ${pathToProject}/app/src/main/cpp/DetectionBasedTracker_jni.cpp)

# 动态方式加载
add_library(lib_opencv SHARED IMPORTED)
# 引入libopencv_java3.so文件
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${pathToProject}/app/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)

target_link_libraries(detection_based_tracker lib_opencv log)

###非正常情况

####无法使用导入的包

#####Question

Unused import statement

#####Why

<>是在系统默认的目录里找头文件,""是在和你的当前代码文件相同的目录里找头文件。源代码不严谨,所以此处找不到文件。

#####Answer

修改代码#include <DetectionBasedTracker_jni.h>#include "DetectionBasedTracker_jni.h"

####函数未定义

#####Question

undefined reference to `__android_log_print'

#####Why

OpenCV SDK 中的 liblog.so 未导入。

#####Answer

target_link_libraries(log)

#测试

运行成功。

(结果与【Eclipse 导入 OpenCV 工程之 face-detection】一致)


face_detection's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.