Skip to content

Commit f3be575

Browse files
Merge pull request #5 from sweetdream779/dlib-opencv-tf
Dlib opencv tf
2 parents e606a10 + 01348d4 commit f3be575

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+12706
-12
lines changed

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "dlib"]
22
path = dlib
3-
url = https://github.com/hoopoe/dlib.git
4-
branch = android
3+
url = git://github.com/hoopoe/dlib.git
4+
branch = android

FaceTracker/app/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
# value of 3.4.0 or lower.
44

55
cmake_minimum_required(VERSION 3.4.1)
6-
6+
set(CMAKE_VERBOSE_MAKEFILE on)
77
set (CMAKE_CXX_STANDARD 11)
88

9-
10-
# OpenCV stuff
119
include_directories($ENV{OPENCV_ANDROID_SDK}/sdk/native/jni/include)
1210
add_library( lib_opencv SHARED IMPORTED )
1311
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION $ENV{OPENCV_ANDROID_SDK}/sdk/native/libs/${ANDROID_ABI}/libopencv_java3.so)
@@ -84,4 +82,6 @@ target_link_libraries(
8482

8583
lib_opencv
8684

87-
${log-lib} )
85+
${log-lib} )
86+
87+
add_subdirectory("./jni")

FaceTracker/app/build.gradle

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
apply plugin: 'com.android.application'
22

3+
def cpuType = 'arm64-v8a'
4+
5+
// Output directory in the local directory for packaging into the APK.
6+
37
android {
48
signingConfigs {
59
config {
@@ -13,15 +17,15 @@ android {
1317
buildToolsVersion '27.0.3'
1418
defaultConfig {
1519
applicationId "com.google.android.gms.samples.vision.face.facetracker"
16-
minSdkVersion 15
20+
minSdkVersion 21
1721
targetSdkVersion 23
1822
versionCode 1
1923
versionName "1.0"
2024
externalNativeBuild {
2125
cmake {
22-
cppFlags "-frtti -fexceptions"
23-
//abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
24-
abiFilters 'armeabi-v7a'
26+
cppFlags "-frtti -fexceptions -std=c++11"
27+
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
28+
//abiFilters "${cpuType}"
2529
arguments "-DANDROID_STL=gnustl_shared"
2630
//arguments "-DANDROID_STL=c++_shared"
2731
// AL: arguments "-DANDROID_STL=c++_shared", "-DBUILD_opencv_apps:BOOL=ON", "-DBUILD_SHARED_LIBS:BOOL=ON"
@@ -84,4 +88,5 @@ dependencies {
8488
implementation 'com.android.support:design:23.4.0'
8589
implementation 'com.google.android.gms:play-services-vision:9.4.0+'
8690
implementation 'com.shamanland:xdroid-toaster:0.2.4'
91+
implementation 'org.tensorflow:tensorflow-android:+'
8792
}

FaceTracker/app/jni/CMakeLists.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#
2+
# Copyright (C) 2016 The Android Open Source Project
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
project(TENSORFLOW_DETECTOR)
17+
cmake_minimum_required(VERSION 3.4.1)
18+
19+
set(CMAKE_VERBOSE_MAKEFILE on)
20+
21+
get_filename_component(SAMPLE_SRC_DIR ${CMAKE_SOURCE_DIR}/ ABSOLUTE)
22+
23+
if (ANDROID_ABI MATCHES "^armeabi-v7a$")
24+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=softfp -mfpu=neon")
25+
elseif(ANDROID_ABI MATCHES "^arm64-v8a")
26+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -ftree-vectorize")
27+
endif()
28+
29+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTANDALONE_DEMO_LIB \
30+
-std=c++11 -fno-exceptions -fno-rtti -O2 -Wno-narrowing \
31+
-fPIE")
32+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} \
33+
-Wl,--allow-multiple-definition \
34+
-Wl,--whole-archive -fPIE -v")
35+
36+
file(GLOB_RECURSE tensorflow_detector_sources ${SAMPLE_SRC_DIR}/jni/*.*)
37+
38+
find_library( # Sets the name of the path variable.
39+
log-lib
40+
41+
# Specifies the name of the NDK library that
42+
# you want CMake to locate.
43+
log )
44+
45+
add_library(tensorflow_detector SHARED
46+
${tensorflow_detector_sources})
47+
target_include_directories(tensorflow_detector PRIVATE
48+
${CMAKE_SOURCE_DIR})
49+
50+
target_link_libraries(tensorflow_detector
51+
android
52+
log
53+
jnigraphics
54+
m
55+
atomic
56+
z)

FaceTracker/app/jni/__init__.py

Whitespace-only changes.

FaceTracker/app/jni/imageutils_jni.cc

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================*/
15+
16+
// This file binds the native image utility code to the Java class
17+
// which exposes them.
18+
19+
#include <jni.h>
20+
#include <stdio.h>
21+
#include <stdlib.h>
22+
23+
#include "rgb2yuv.h"
24+
#include "yuv2rgb.h"
25+
26+
#define IMAGEUTILS_METHOD(METHOD_NAME) \
27+
Java_tensorflow_detector_spc_env_ImageUtils_##METHOD_NAME // NOLINT
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
JNIEXPORT void JNICALL
34+
IMAGEUTILS_METHOD(convertYUV420SPToARGB8888)(
35+
JNIEnv* env, jclass clazz, jbyteArray input, jintArray output,
36+
jint width, jint height, jboolean halfSize);
37+
38+
JNIEXPORT void JNICALL IMAGEUTILS_METHOD(convertYUV420ToARGB8888)(
39+
JNIEnv* env, jclass clazz, jbyteArray y, jbyteArray u, jbyteArray v,
40+
jintArray output, jint width, jint height, jint y_row_stride,
41+
jint uv_row_stride, jint uv_pixel_stride, jboolean halfSize);
42+
43+
JNIEXPORT void JNICALL IMAGEUTILS_METHOD(convertYUV420SPToRGB565)(
44+
JNIEnv* env, jclass clazz, jbyteArray input, jbyteArray output, jint width,
45+
jint height);
46+
47+
JNIEXPORT void JNICALL
48+
IMAGEUTILS_METHOD(convertARGB8888ToYUV420SP)(
49+
JNIEnv* env, jclass clazz, jintArray input, jbyteArray output,
50+
jint width, jint height);
51+
52+
JNIEXPORT void JNICALL
53+
IMAGEUTILS_METHOD(convertRGB565ToYUV420SP)(
54+
JNIEnv* env, jclass clazz, jbyteArray input, jbyteArray output,
55+
jint width, jint height);
56+
57+
#ifdef __cplusplus
58+
}
59+
#endif
60+
61+
JNIEXPORT void JNICALL
62+
IMAGEUTILS_METHOD(convertYUV420SPToARGB8888)(
63+
JNIEnv* env, jclass clazz, jbyteArray input, jintArray output,
64+
jint width, jint height, jboolean halfSize) {
65+
jboolean inputCopy = JNI_FALSE;
66+
jbyte* const i = env->GetByteArrayElements(input, &inputCopy);
67+
68+
jboolean outputCopy = JNI_FALSE;
69+
jint* const o = env->GetIntArrayElements(output, &outputCopy);
70+
71+
if (halfSize) {
72+
ConvertYUV420SPToARGB8888HalfSize(reinterpret_cast<uint8_t*>(i),
73+
reinterpret_cast<uint32_t*>(o), width,
74+
height);
75+
} else {
76+
ConvertYUV420SPToARGB8888(reinterpret_cast<uint8_t*>(i),
77+
reinterpret_cast<uint8_t*>(i) + width * height,
78+
reinterpret_cast<uint32_t*>(o), width, height);
79+
}
80+
81+
env->ReleaseByteArrayElements(input, i, JNI_ABORT);
82+
env->ReleaseIntArrayElements(output, o, 0);
83+
}
84+
85+
JNIEXPORT void JNICALL IMAGEUTILS_METHOD(convertYUV420ToARGB8888)(
86+
JNIEnv* env, jclass clazz, jbyteArray y, jbyteArray u, jbyteArray v,
87+
jintArray output, jint width, jint height, jint y_row_stride,
88+
jint uv_row_stride, jint uv_pixel_stride, jboolean halfSize) {
89+
jboolean inputCopy = JNI_FALSE;
90+
jbyte* const y_buff = env->GetByteArrayElements(y, &inputCopy);
91+
jboolean outputCopy = JNI_FALSE;
92+
jint* const o = env->GetIntArrayElements(output, &outputCopy);
93+
94+
if (halfSize) {
95+
ConvertYUV420SPToARGB8888HalfSize(reinterpret_cast<uint8_t*>(y_buff),
96+
reinterpret_cast<uint32_t*>(o), width,
97+
height);
98+
} else {
99+
jbyte* const u_buff = env->GetByteArrayElements(u, &inputCopy);
100+
jbyte* const v_buff = env->GetByteArrayElements(v, &inputCopy);
101+
102+
ConvertYUV420ToARGB8888(
103+
reinterpret_cast<uint8_t*>(y_buff), reinterpret_cast<uint8_t*>(u_buff),
104+
reinterpret_cast<uint8_t*>(v_buff), reinterpret_cast<uint32_t*>(o),
105+
width, height, y_row_stride, uv_row_stride, uv_pixel_stride);
106+
107+
env->ReleaseByteArrayElements(u, u_buff, JNI_ABORT);
108+
env->ReleaseByteArrayElements(v, v_buff, JNI_ABORT);
109+
}
110+
111+
env->ReleaseByteArrayElements(y, y_buff, JNI_ABORT);
112+
env->ReleaseIntArrayElements(output, o, 0);
113+
}
114+
115+
JNIEXPORT void JNICALL IMAGEUTILS_METHOD(convertYUV420SPToRGB565)(
116+
JNIEnv* env, jclass clazz, jbyteArray input, jbyteArray output, jint width,
117+
jint height) {
118+
jboolean inputCopy = JNI_FALSE;
119+
jbyte* const i = env->GetByteArrayElements(input, &inputCopy);
120+
121+
jboolean outputCopy = JNI_FALSE;
122+
jbyte* const o = env->GetByteArrayElements(output, &outputCopy);
123+
124+
ConvertYUV420SPToRGB565(reinterpret_cast<uint8_t*>(i),
125+
reinterpret_cast<uint16_t*>(o), width, height);
126+
127+
env->ReleaseByteArrayElements(input, i, JNI_ABORT);
128+
env->ReleaseByteArrayElements(output, o, 0);
129+
}
130+
131+
JNIEXPORT void JNICALL
132+
IMAGEUTILS_METHOD(convertARGB8888ToYUV420SP)(
133+
JNIEnv* env, jclass clazz, jintArray input, jbyteArray output,
134+
jint width, jint height) {
135+
jboolean inputCopy = JNI_FALSE;
136+
jint* const i = env->GetIntArrayElements(input, &inputCopy);
137+
138+
jboolean outputCopy = JNI_FALSE;
139+
jbyte* const o = env->GetByteArrayElements(output, &outputCopy);
140+
141+
ConvertARGB8888ToYUV420SP(reinterpret_cast<uint32_t*>(i),
142+
reinterpret_cast<uint8_t*>(o), width, height);
143+
144+
env->ReleaseIntArrayElements(input, i, JNI_ABORT);
145+
env->ReleaseByteArrayElements(output, o, 0);
146+
}
147+
148+
JNIEXPORT void JNICALL
149+
IMAGEUTILS_METHOD(convertRGB565ToYUV420SP)(
150+
JNIEnv* env, jclass clazz, jbyteArray input, jbyteArray output,
151+
jint width, jint height) {
152+
jboolean inputCopy = JNI_FALSE;
153+
jbyte* const i = env->GetByteArrayElements(input, &inputCopy);
154+
155+
jboolean outputCopy = JNI_FALSE;
156+
jbyte* const o = env->GetByteArrayElements(output, &outputCopy);
157+
158+
ConvertRGB565ToYUV420SP(reinterpret_cast<uint16_t*>(i),
159+
reinterpret_cast<uint8_t*>(o), width, height);
160+
161+
env->ReleaseByteArrayElements(input, i, JNI_ABORT);
162+
env->ReleaseByteArrayElements(output, o, 0);
163+
}

0 commit comments

Comments
 (0)