Skip to content

Commit

Permalink
detect faces
Browse files Browse the repository at this point in the history
  • Loading branch information
vkocheryzhkin committed Mar 19, 2018
1 parent 6d8dc5f commit 76019e4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
16 changes: 14 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
apply plugin: 'com.android.application'

android {
signingConfigs {
config {
keyAlias 'test'
keyPassword 'zhuk123321'
storeFile file('E:/Work/dlib_opencv_android_apk/test.jks')
storePassword 'zhuk123321'
}
}
compileSdkVersion 27
defaultConfig {
applicationId "ch.hepia.iti.opencvnativeandroidstudio"
Expand All @@ -12,11 +20,12 @@ android {
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
//abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
abiFilters 'x86'
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
abiFilters 'x86', 'armeabi', 'armeabi-v7a'
arguments "-DANDROID_STL=c++_shared"
}
}
signingConfig signingConfigs.config
}
sourceSets {
main {
Expand All @@ -27,13 +36,16 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
productFlavors {
}
}

dependencies {
Expand Down
35 changes: 15 additions & 20 deletions app/src/main/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <dlib/opencv.h>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing.h>

#include <android/log.h>

Expand All @@ -19,25 +20,19 @@ extern "C"
jlong matAddrGray,
jint nbrElem) {
Mat &temp = *(Mat *) matAddrGray;

// dlib::array2d<unsigned char> dlibImage;
// dlib::assign_image(dlibImage, dlib::cv_image<unsigned char>(temp));
// std::vector<dlib::rectangle> dets = detector(dlibImage);
//dlib::cv_image<unsigned char> cimg(temp);

//std::vector<dlib::rectangle> dets = detector(cimg);

int x = 0;
int y = 0;
int width = 100;
int height = 200;
cv::Rect rect(x, y, width, height);
cv::rectangle(temp, rect, cv::Scalar(255));//0, 255, 0));

// for (int k = 0; k < nbrElem; k++) {
// int i = rand() % mGr.cols;
// int j = rand() % mGr.rows;
// mGr.at<uchar>(j, i) = 255;
// }
dlib::cv_image<unsigned char> cimg(temp);
std::vector<dlib::rectangle> dets = detector(cimg);

for(auto i : dets)
{
int x = i.left();
int y = i.top();
int width = i.width();
int height = i.height();
cv::Rect rect(x, y, width, height);
cv::rectangle(temp, rect, cv::Scalar(255));//0, 255, 0));
}

__android_log_print(ANDROID_LOG_INFO, "App", "Number of rectangles = %d", dets.size());
}
}

0 comments on commit 76019e4

Please sign in to comment.