Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Suaro committed Mar 24, 2021
2 parents f7b5f86 + c2dc514 commit 08e8ed7
Show file tree
Hide file tree
Showing 23 changed files with 347 additions and 126 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ This library currently is full developed in Kotlin with C++, no additional depen
- [x] Face detection
- [x] Pupil detection
- [x] Landmarks detection
- [x] Pure Java Pidroid (to delete avoid Kotlin dependency)
- [ ] Publish Library as Github Package
- [ ] Pure Java Pidroid (to delete avoid Kotlin dependency)
- [ ] Rotated faces detection
- [ ] Neon support
- [ ] SSE support
- [ ] Tegra support


## Usage
Expand Down Expand Up @@ -156,11 +155,11 @@ All configuration parameters are in PidroidConfig class.
| maxsize | Max radius of faces detected | 1000 |
| prominentFaceOnly | Parameter that determines if you want to return only the most predominant face | False |
| clustering | This parameter groups detections to prevent a face from being detected multiple times | True |
| stridefactorWidth | This parameter determines how many pixels the sliding window is moved to detect. For example, if the value is 0.1 and the image is 1000 pixels wide, the sliding window will move every 100 pixels. | 0.2 |
| stridefactorHeight | Same as stridefactorWidth but for height | 0.12 |
| stridefactorWidth | This parameter determines how many pixels the sliding window is moved to detect. For example, if the value is 0.1 and the image is 1000 pixels wide, the sliding window will move every 100 pixels. | 0.1 |
| stridefactorHeight | Same as stridefactorWidth but for height | 0.1 |
| scalefactor | The PICO algorithm searches for different face sizes starting from minsize to maxsize. This parameter determines how much the search size increases each iteration. | 1.1 |
| qthreshold | Minimum threshold to consider a region as a face. | 3.0 |
| perturbs | The detection of pupils and landmarks, start from an initial region to predict the exact position. This initial region is disturbed N times to increase the precision of detection. This also makes the method slower the larger this parameter grows. | 24 |
| perturbs | The detection of pupils and landmarks, start from an initial region to predict the exact position. This initial region is disturbed N times to increase the precision of detection. This also makes the method slower the larger this parameter grows. | 10 |
| pupilDetectionEnable | This parameter enable pupil detection | True |
| landmarkDetectionEnable | This parameter enable landmark detection. Its mandatory pupilDetectionEnable to True to detect landmarks. | True |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ class CanvasView @JvmOverloads constructor(context: Context, attrs: AttributeSet
paint.setColor(color)
paint.setStrokeWidth(RECT_BORDER_WIDTH);

canvas?.drawRoundRect(rect.left.toFloat(), rect.top.toFloat(), rect.right.toFloat(), rect.bottom.toFloat(), RECT_BORDER_RADIUS, RECT_BORDER_RADIUS, paint);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
canvas?.drawRoundRect(rect.left.toFloat(), rect.top.toFloat(), rect.right.toFloat(), rect.bottom.toFloat(), RECT_BORDER_RADIUS, RECT_BORDER_RADIUS, paint)
} else {
canvas?.drawRect(rect, paint)
}
}

fun drawCircle(circle: Circle, canvas: Canvas?, color: Int = Color.GREEN) {;
Expand Down
19 changes: 11 additions & 8 deletions imagesample/src/main/java/com/suaro/imagesample/ImageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,26 @@ class ImageActivity : AppCompatActivity() {
val handler: Handler = Handler();

handler.postDelayed({
val drawable: BitmapDrawable = imageTest.getDrawable() as BitmapDrawable
val bitmap: Bitmap = drawable.bitmap
canvasView.setAspectRatio(bitmap.width, bitmap.height)
val dinfo = callDetectFace(bitmap)
drawResult(dinfo)

}, 1000)
performFaceDetection()
}, 100)
}

override fun onDestroy() {
super.onDestroy()
}

private fun performFaceDetection() {
val drawable: BitmapDrawable = imageTest.getDrawable() as BitmapDrawable
val bitmap: Bitmap = drawable.bitmap
canvasView.setAspectRatio(bitmap.width, bitmap.height)
val dinfo = callDetectFace(bitmap)
drawResult(dinfo)
}

fun callDetectFace(bitmap: Bitmap): FaceDetectionResult {
val pixels = IntArray(bitmap.width * bitmap.height * 4)
bitmap.getPixels(pixels, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height)
var dInfo = FaceDetectionResult()
val dInfo = FaceDetectionResult()
Pidroid.detectFace(pixels, bitmap.width, bitmap.height, dInfo)
return dInfo
}
Expand Down
2 changes: 1 addition & 1 deletion imagesample/src/main/res/layout/activity_image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:layout_height="0dp"
android:adjustViewBounds="true"
android:keepScreenOn="true"
app:srcCompat="@drawable/friends"
app:srcCompat="@drawable/tonystark"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
10 changes: 2 additions & 8 deletions pidroid/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
}

android {
Expand All @@ -10,8 +9,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down Expand Up @@ -44,9 +43,6 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
externalNativeBuild {
cmake {
path file('CMakeLists.txt')
Expand All @@ -56,8 +52,6 @@ android {
}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
Expand Down
4 changes: 2 additions & 2 deletions pidroid/src/main/cpp/pidroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {

extern "C"
JNIEXPORT void JNICALL
Java_com_suaro_pidroid_core_NativeMethods_00024Companion_setup(JNIEnv *env, jobject thiz, jobject pidroidConfig, jobject assetManager) {
Java_com_suaro_pidroid_core_NativeMethods_setup(JNIEnv *env, jobject thiz, jobject pidroidConfig, jobject assetManager) {

pidroid = pidroidlib::Pidroid();
pidroid.setup(env, thiz, pidroidConfig, assetManager);
Expand All @@ -54,7 +54,7 @@ Java_com_suaro_pidroid_core_NativeMethods_00024Companion_setup(JNIEnv *env, jobj

extern "C"
JNIEXPORT void JNICALL
Java_com_suaro_pidroid_core_NativeMethods_00024Companion_detectFace(JNIEnv *env, jobject thiz,
Java_com_suaro_pidroid_core_NativeMethods_detectFace(JNIEnv *env, jobject thiz,
jintArray rgbaBytes, jint width,
jint height,
jobject detection_info) {
Expand Down
33 changes: 33 additions & 0 deletions pidroid/src/main/java/com/suaro/pidroid/Pidroid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.suaro.pidroid;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;

import com.suaro.pidroid.core.FaceDetectionResult;
import com.suaro.pidroid.core.NativeMethods;
import com.suaro.pidroid.core.PidroidConfig;

import org.jetbrains.annotations.NotNull;


public final class Pidroid {
private static AssetManager mgr;
private static PidroidConfig cascadeConfig;



public static void setup(@NotNull Context context, @NotNull PidroidConfig config) {
mgr = context.getResources().getAssets();
cascadeConfig = config;
NativeMethods.setup(cascadeConfig, mgr);
}

public static void detectFace(@NotNull int[] byteArray, int width, int height, @NotNull FaceDetectionResult dInfo) {
NativeMethods.detectFace(byteArray, width, height, dInfo);
}

private Pidroid() {
}

}
27 changes: 0 additions & 27 deletions pidroid/src/main/java/com/suaro/pidroid/Pidroid.kt

This file was deleted.

25 changes: 25 additions & 0 deletions pidroid/src/main/java/com/suaro/pidroid/core/Eye.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.suaro.pidroid.core;

import org.jetbrains.annotations.NotNull;

public final class Eye {
private Point center = new Point(0, 0);
private int radius;

@NotNull
public final Point getCenter() {
return this.center;
}

public final void setCenter(@NotNull Point point) {
this.center = point;
}

public final int getRadius() {
return this.radius;
}

public final void setRadius(int rad) {
this.radius = rad;
}
}
6 changes: 0 additions & 6 deletions pidroid/src/main/java/com/suaro/pidroid/core/Eye.kt

This file was deleted.

63 changes: 63 additions & 0 deletions pidroid/src/main/java/com/suaro/pidroid/core/Face.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.suaro.pidroid.core;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;


public final class Face {

@NotNull
private Point topLeft = new Point(0, 0);
private int width;
private int height;

@NotNull
private ArrayList<Eye> eyes = new ArrayList<Eye>();

@NotNull
private ArrayList<Landmark> landmarks = new ArrayList<Landmark>();

@NotNull
public final Point getTopLeft() {
return this.topLeft;
}

public final void setTopLeft(@NotNull Point topLeft) {
this.topLeft = topLeft;
}

public final int getWidth() {
return this.width;
}

public final void setWidth(int width) {
this.width = width;
}

public final int getHeight() {
return this.height;
}

public final void setHeight(int height) {
this.height = height;
}

@NotNull
public final ArrayList<Eye> getEyes() {
return this.eyes;
}

public final void setEyes(@NotNull ArrayList<Eye> eyes) {
this.eyes = eyes;
}

@NotNull
public final ArrayList<Landmark> getLandmarks() {
return this.landmarks;
}

public final void setLandmarks(@NotNull ArrayList<Landmark> landmarks) {
this.landmarks = landmarks;
}
}
9 changes: 0 additions & 9 deletions pidroid/src/main/java/com/suaro/pidroid/core/Face.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.suaro.pidroid.core;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public final class FaceDetectionResult {
@NotNull
private ArrayList<Face> faces = new ArrayList<Face>();
private boolean detected;

@NotNull
public final ArrayList<Face> getFaces() {
return this.faces;
}

public final void setFaces(@NotNull ArrayList<Face> faces) {
this.faces = faces;
}

public final boolean getDetected() {
return this.detected;
}

public final void setDetected(boolean detected) {
this.detected = detected;
}
}

This file was deleted.

26 changes: 26 additions & 0 deletions pidroid/src/main/java/com/suaro/pidroid/core/Landmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.suaro.pidroid.core;

import org.jetbrains.annotations.NotNull;

public final class Landmark {
@NotNull
private Point center = new Point(0, 0);
private int radius;

@NotNull
public final Point getCenter() {
return this.center;
}

public final void setCenter(@NotNull Point center) {
this.center = center;
}

public final int getRadius() {
return this.radius;
}

public final void setRadius(int radius) {
this.radius = radius;
}
}
6 changes: 0 additions & 6 deletions pidroid/src/main/java/com/suaro/pidroid/core/Landmark.kt

This file was deleted.

Loading

0 comments on commit 08e8ed7

Please sign in to comment.