Skip to content

Commit df71024

Browse files
Merge pull request #2 from hoopoe/AS-OpenCV-DLib-2modules
As open cv d lib 2modules
2 parents f58b237 + 8d299cb commit df71024

File tree

5 files changed

+116
-24
lines changed

5 files changed

+116
-24
lines changed

dlib

Submodule dlib updated from 803a27b to 7ee6c36

visionSamples/FaceTracker/app/CMakeLists.txt

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Sets the minimum version of CMake required to build the native
32
# library. You should either keep the default value or only pass a
43
# value of 3.4.0 or lower.
@@ -7,8 +6,24 @@ cmake_minimum_required(VERSION 3.4.1)
76

87
set (CMAKE_CXX_STANDARD 11)
98

9+
10+
# OpenCV stuff
11+
# todo: use env variable to set opencv location
12+
include_directories("/Users/hoopoe/Tools/OpenCV-android-sdk/sdk/native/jni/include")
13+
add_library( lib_opencv SHARED IMPORTED )
14+
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION /Users/hoopoe/Tools/OpenCV-android-sdk/sdk/native/libs/${ANDROID_ABI}/libopencv_java3.so)
15+
16+
find_library( # Sets the name of the path variable.
17+
log-lib
18+
19+
# Specifies the name of the NDK library that
20+
# you want CMake to locate.
21+
log )
22+
1023
set(DLIB_DIR ../../../dlib)
1124
include_directories(${DLIB_DIR})
25+
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
26+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
1227

1328
add_library( # Sets the name of the library.
1429
lib_dlib
@@ -41,24 +56,6 @@ add_library( # Sets the name of the library.
4156
# file are automatically included.
4257
src/main/cpp/native-lib.cpp )
4358

44-
45-
# Searches for a specified prebuilt library and stores the path as a
46-
# variable. Because system libraries are included in the search path by
47-
# default, you only need to specify the name of the public NDK library
48-
# you want to add. CMake verifies that the library exists before
49-
# completing its build.
50-
51-
find_library( # Sets the name of the path variable.
52-
log-lib
53-
54-
# Specifies the name of the NDK library that
55-
# you want CMake to locate.
56-
log )
57-
58-
# Specifies libraries CMake should link to your target library. You
59-
# can link multiple libraries, such as libraries you define in the
60-
# build script, prebuilt third-party libraries, or system libraries.
61-
6259
target_link_libraries( # Specifies the target library.
6360
native-lib
6461

@@ -68,4 +65,24 @@ target_link_libraries( # Specifies the target library.
6865

6966
# Links the target library to the log library
7067
# included in the NDK.
68+
${log-lib} )
69+
70+
71+
72+
add_library( # Sets the name of the library.
73+
OCV-native-lib
74+
75+
# Sets the library as a shared library.
76+
SHARED
77+
78+
# Provides a relative path to your source file(s).
79+
# Associated headers in the same location as their source
80+
# file are automatically included.
81+
src/main/cpp/OCV-native-lib.cpp )
82+
83+
target_link_libraries(
84+
OCV-native-lib
85+
86+
lib_opencv
87+
7188
${log-lib} )

visionSamples/FaceTracker/app/build.gradle

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,44 @@ android {
2020
externalNativeBuild {
2121
cmake {
2222
cppFlags "-frtti -fexceptions"
23-
abiFilters 'x86', 'x86_64', 'armeabi-v7a'
24-
arguments "-DANDROID_STL=c++_shared"
23+
//abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
24+
abiFilters 'armeabi-v7a'
25+
arguments "-DANDROID_STL=gnustl_shared"
26+
//arguments "-DANDROID_STL=c++_shared"
27+
// AL: arguments "-DANDROID_STL=c++_shared", "-DBUILD_opencv_apps:BOOL=ON", "-DBUILD_SHARED_LIBS:BOOL=ON"
2528
// Passes optional arguments to CMake.
2629
//arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_TOOLCHAIN=clang"
2730

2831
// Sets a flag to enable format macro constants for the C compiler.
2932
//cFlags "-D__STDC_FORMAT_MACROS"
30-
3133
}
3234
}
3335
signingConfig signingConfigs.config
3436
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
3537
}
38+
39+
// sourceSets { // AL: added
40+
// main {
41+
// jniLibs.srcDirs = ['src/main/jniLibs']
42+
// jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/']
43+
// //jni.srcDirs = []
44+
// }
45+
// }
46+
3647
buildTypes {
3748
release {
3849
minifyEnabled false
3950
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4051
signingConfig signingConfigs.config
4152
}
4253
}
54+
55+
externalNativeBuild {
56+
cmake {
57+
path "CMakeLists.txt"
58+
}
59+
}
60+
4361
testBuildType "release"
4462
externalNativeBuild {
4563
cmake {
@@ -54,6 +72,7 @@ android {
5472
}
5573

5674
dependencies {
75+
implementation fileTree(include: ['*.jar'], dir: 'libs')
5776
androidTestImplementation 'junit:junit:4.12'
5877
implementation 'com.android.support:support-annotations:27.1.1'
5978
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <jni.h>
2+
#include <string>
3+
#include <opencv2/opencv.hpp>
4+
5+
/* these seem not needed */
6+
#include <opencv2/core/core.hpp>
7+
#include <opencv2/imgproc/imgproc.hpp>
8+
#include <opencv2/objdetect/objdetect.hpp>
9+
#include <opencv2/objdetect/detection_based_tracker.hpp>
10+
#include <opencv2/features2d/features2d.hpp>
11+
12+
#include <android/log.h>
13+
14+
using namespace std;
15+
using namespace cv;
16+
17+
#define AppTag "OCV-FD::Activity"
18+
19+
extern "C"
20+
{
21+
22+
23+
void detect(Mat &gray) {
24+
25+
String face_cascade_name = "/storage/emulated/0/Movies/haarcascade_frontalface_default.xml";
26+
27+
CascadeClassifier face_cascade;
28+
std::vector<Rect> faces;
29+
30+
if( !face_cascade.load( face_cascade_name ) ){
31+
printf("--(!)Error loading\n");
32+
__android_log_print(ANDROID_LOG_DEBUG, AppTag, "Resources NOT found: exiting");
33+
return;
34+
}
35+
36+
face_cascade.detectMultiScale(gray,faces,1.1,3,0,Size(20,20),Size(1000,1000));
37+
38+
for(size_t i=0; i<faces.size(); i++)
39+
{
40+
rectangle(gray,faces[i],cv::Scalar(255, 255, 255), 2, 8, 0);
41+
}
42+
}
43+
44+
45+
void JNICALL
46+
Java_ch_hepia_iti_opencvnativeandroidstudio_MainActivity_imgProcess(JNIEnv *env, jclass,
47+
jlong inputAddrMat,
48+
jlong imageAddrGray) {
49+
Mat &mRgb = *(Mat *)inputAddrMat;
50+
Mat &mGray = *(Mat *)imageAddrGray;
51+
52+
detect (mGray);
53+
}
54+
55+
}

visionSamples/FaceTracker/gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
# When configured, Gradle will run in incubating parallel mode.
1616
# This option should only be used with decoupled projects. More details, visit
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18-
# org.gradle.parallel=true
18+
# org.gradle.parallel=true
19+
android.useDeprecatedNdk=true

0 commit comments

Comments
 (0)