Skip to content

Commit

Permalink
export face detect as library project & rename jni library
Browse files Browse the repository at this point in the history
  • Loading branch information
CMingTseng committed Oct 22, 2022
1 parent e69fd1b commit 538eb4c
Show file tree
Hide file tree
Showing 2,071 changed files with 583 additions and 513 deletions.
1 change: 1 addition & 0 deletions opencv_face_detect/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
154 changes: 77 additions & 77 deletions app/CMakeLists.txt → opencv_face_detect/CMakeLists.txt
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

# 设置native目录
set(NATIVE_DIR ${CMAKE_SOURCE_DIR}/src/main/cpp)

# 设置dlib
include(${NATIVE_DIR}/dlib/cmake)

# 设置opencv include文件夹
include_directories(${NATIVE_DIR}/opencv/jni/include)

# 设置opencv so库
add_library(
libopencv_java3
SHARED
IMPORTED)

set_target_properties(
libopencv_java3
PROPERTIES
IMPORTED_LOCATION
${NATIVE_DIR}/opencv/libs/${ANDROID_ABI}/libopencv_java3.so)

# 将jni_common目录中所有文件名,存至SRC_LIST中
AUX_SOURCE_DIRECTORY(${NATIVE_DIR}/jni_common SRC_LIST)

add_library( # Sets the name of the library.
native-lib

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).

${SRC_LIST}
src/main/cpp/face_detector.h
src/main/cpp/face_detector.cpp
src/main/cpp/native-lib.cpp)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
log-lib

# Specifies the name of the NDK library that
# you want CMake to locate.
log)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
native-lib
dlib
libopencv_java3
jnigraphics
# Links the target library to the log library
# included in the NDK.
${log-lib})

# 指定release编译选项
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s -O3 -Wall")
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

# 设置native目录
set(NATIVE_DIR ${CMAKE_SOURCE_DIR}/src/main/cpp)

# 设置dlib
include(${NATIVE_DIR}/dlib/cmake)

# 设置opencv include文件夹
include_directories(${NATIVE_DIR}/opencv/jni/include)

# 设置opencv so库
add_library(
libopencv_java3
SHARED
IMPORTED)

set_target_properties(
libopencv_java3
PROPERTIES
IMPORTED_LOCATION
${NATIVE_DIR}/opencv/libs/${ANDROID_ABI}/libopencv_java3.so)

# 将jni_common目录中所有文件名,存至SRC_LIST中
AUX_SOURCE_DIRECTORY(${NATIVE_DIR}/jni_common SRC_LIST)

add_library( # Sets the name of the library.
facedetec-lib

# Sets the library as a shared library.
SHARED

# Provides a relative path to your source file(s).

${SRC_LIST}
src/main/cpp/face_detector.h
src/main/cpp/face_detector.cpp
src/main/cpp/native-lib.cpp)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
log-lib

# Specifies the name of the NDK library that
# you want CMake to locate.
log)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
facedetec-lib
dlib
libopencv_java3
jnigraphics
# Links the target library to the log library
# included in the NDK.
${log-lib})

# 指定release编译选项
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s -O3 -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s -O3 -Wall")
43 changes: 43 additions & 0 deletions opencv_face_detect/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 32
//TODO the NDK must pass build must set spec ndkVersion , can not over 21.X.XXXXXXX
ndkVersion "21.4.7075529"//20.0.5594570 21.0.6113669 21.1.6352462 21.4.7075529 21.4.7075529 //Ref : https://developer.android.com/studio/projects/install-ndk
defaultConfig {
minSdkVersion 21
targetSdkVersion 32
versionCode 1
versionName "1.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
externalNativeBuild {
cmake {
arguments "-DCMAKE_BUILD_TYPE=Release"
cppFlags "-std=c++11 -frtti -fexceptions"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets {
main {
}
}
}

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.annotation:annotation:1.5.0'
}
Loading

0 comments on commit 538eb4c

Please sign in to comment.