From 8d6b755297200e13cd32a8aab70ac748ba6a31c5 Mon Sep 17 00:00:00 2001 From: Suaro Date: Wed, 24 Mar 2021 23:07:47 +0100 Subject: [PATCH 1/4] Remove kotlin dependency --- pidroid/build.gradle | 6 - pidroid/src/main/cpp/pidroid.cpp | 4 +- .../main/java/com/suaro/pidroid/Pidroid.java | 33 ++++++ .../main/java/com/suaro/pidroid/Pidroid.kt | 27 ----- .../main/java/com/suaro/pidroid/core/Eye.java | 25 +++++ .../main/java/com/suaro/pidroid/core/Eye.kt | 6 - .../java/com/suaro/pidroid/core/Face.java | 63 +++++++++++ .../main/java/com/suaro/pidroid/core/Face.kt | 9 -- .../pidroid/core/FaceDetectionResult.java | 28 +++++ .../suaro/pidroid/core/FaceDetectionResult.kt | 9 -- .../java/com/suaro/pidroid/core/Landmark.java | 26 +++++ .../java/com/suaro/pidroid/core/Landmark.kt | 6 - .../com/suaro/pidroid/core/NativeMethods.java | 15 +++ .../com/suaro/pidroid/core/NativeMethods.kt | 16 --- .../com/suaro/pidroid/core/PidroidConfig.java | 103 ++++++++++++++++++ .../com/suaro/pidroid/core/PidroidConfig.kt | 23 ---- .../java/com/suaro/pidroid/core/Point.java | 27 +++++ .../main/java/com/suaro/pidroid/core/Point.kt | 5 - .../com/suaro/realtimesample/MainActivity.kt | 1 + 19 files changed, 323 insertions(+), 109 deletions(-) create mode 100644 pidroid/src/main/java/com/suaro/pidroid/Pidroid.java delete mode 100644 pidroid/src/main/java/com/suaro/pidroid/Pidroid.kt create mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/Eye.java delete mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/Eye.kt create mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/Face.java delete mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/Face.kt create mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/FaceDetectionResult.java delete mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/FaceDetectionResult.kt create mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/Landmark.java delete mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/Landmark.kt create mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/NativeMethods.java delete mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/NativeMethods.kt create mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.java delete mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.kt create mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/Point.java delete mode 100644 pidroid/src/main/java/com/suaro/pidroid/core/Point.kt diff --git a/pidroid/build.gradle b/pidroid/build.gradle index da5f745..bddd7ff 100644 --- a/pidroid/build.gradle +++ b/pidroid/build.gradle @@ -1,6 +1,5 @@ plugins { id 'com.android.library' - id 'kotlin-android' } android { @@ -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') @@ -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' diff --git a/pidroid/src/main/cpp/pidroid.cpp b/pidroid/src/main/cpp/pidroid.cpp index 911f925..a61fe1a 100644 --- a/pidroid/src/main/cpp/pidroid.cpp +++ b/pidroid/src/main/cpp/pidroid.cpp @@ -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); @@ -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) { diff --git a/pidroid/src/main/java/com/suaro/pidroid/Pidroid.java b/pidroid/src/main/java/com/suaro/pidroid/Pidroid.java new file mode 100644 index 0000000..4e9a6e4 --- /dev/null +++ b/pidroid/src/main/java/com/suaro/pidroid/Pidroid.java @@ -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() { + } + +} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/Pidroid.kt b/pidroid/src/main/java/com/suaro/pidroid/Pidroid.kt deleted file mode 100644 index 44531fb..0000000 --- a/pidroid/src/main/java/com/suaro/pidroid/Pidroid.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.suaro.pidroid - -import android.content.Context -import android.content.res.AssetManager -import com.suaro.pidroid.core.FaceDetectionResult -import com.suaro.pidroid.core.PidroidConfig -import com.suaro.pidroid.core.NativeMethods - -object Pidroid { - - private lateinit var mgr: AssetManager - private lateinit var cascadeConfig: PidroidConfig - - - fun setup(context: Context, config: PidroidConfig) { - this.mgr = context.resources.assets - this.cascadeConfig = config - - NativeMethods.setup(cascadeConfig, mgr) - } - - fun detectFace(byteArray: IntArray, width: Int, height: Int, dInfo: FaceDetectionResult) { - NativeMethods.detectFace(byteArray, width, height, dInfo); - } - - -} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/Eye.java b/pidroid/src/main/java/com/suaro/pidroid/core/Eye.java new file mode 100644 index 0000000..fb66a31 --- /dev/null +++ b/pidroid/src/main/java/com/suaro/pidroid/core/Eye.java @@ -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; + } +} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/Eye.kt b/pidroid/src/main/java/com/suaro/pidroid/core/Eye.kt deleted file mode 100644 index 5d04360..0000000 --- a/pidroid/src/main/java/com/suaro/pidroid/core/Eye.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.suaro.pidroid.core - -class Eye { - var center: Point = Point(0,0) - var radius: Int = 0 -} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/Face.java b/pidroid/src/main/java/com/suaro/pidroid/core/Face.java new file mode 100644 index 0000000..3359c91 --- /dev/null +++ b/pidroid/src/main/java/com/suaro/pidroid/core/Face.java @@ -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 eyes = new ArrayList(); + + @NotNull + private ArrayList landmarks = new ArrayList(); + + @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 getEyes() { + return this.eyes; + } + + public final void setEyes(@NotNull ArrayList eyes) { + this.eyes = eyes; + } + + @NotNull + public final ArrayList getLandmarks() { + return this.landmarks; + } + + public final void setLandmarks(@NotNull ArrayList landmarks) { + this.landmarks = landmarks; + } +} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/Face.kt b/pidroid/src/main/java/com/suaro/pidroid/core/Face.kt deleted file mode 100644 index 0066c82..0000000 --- a/pidroid/src/main/java/com/suaro/pidroid/core/Face.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.suaro.pidroid.core - -class Face { - var topLeft: Point = Point(0,0) - var width: Int = 0 - var height: Int = 0 - var eyes: ArrayList = ArrayList() - var landmarks: ArrayList = ArrayList() -} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/FaceDetectionResult.java b/pidroid/src/main/java/com/suaro/pidroid/core/FaceDetectionResult.java new file mode 100644 index 0000000..3c9d3fc --- /dev/null +++ b/pidroid/src/main/java/com/suaro/pidroid/core/FaceDetectionResult.java @@ -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 faces = new ArrayList(); + private boolean detected; + + @NotNull + public final ArrayList getFaces() { + return this.faces; + } + + public final void setFaces(@NotNull ArrayList faces) { + this.faces = faces; + } + + public final boolean getDetected() { + return this.detected; + } + + public final void setDetected(boolean detected) { + this.detected = detected; + } +} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/FaceDetectionResult.kt b/pidroid/src/main/java/com/suaro/pidroid/core/FaceDetectionResult.kt deleted file mode 100644 index 3e26e6c..0000000 --- a/pidroid/src/main/java/com/suaro/pidroid/core/FaceDetectionResult.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.suaro.pidroid.core - -class FaceDetectionResult { - - var faces: ArrayList = ArrayList() - var detected:Boolean = false; - - constructor() -} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/Landmark.java b/pidroid/src/main/java/com/suaro/pidroid/core/Landmark.java new file mode 100644 index 0000000..822c1ea --- /dev/null +++ b/pidroid/src/main/java/com/suaro/pidroid/core/Landmark.java @@ -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; + } +} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/Landmark.kt b/pidroid/src/main/java/com/suaro/pidroid/core/Landmark.kt deleted file mode 100644 index 150fed9..0000000 --- a/pidroid/src/main/java/com/suaro/pidroid/core/Landmark.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.suaro.pidroid.core - -class Landmark { - var center: Point = Point(0,0) - var radius: Int = 0 -} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/NativeMethods.java b/pidroid/src/main/java/com/suaro/pidroid/core/NativeMethods.java new file mode 100644 index 0000000..69337ae --- /dev/null +++ b/pidroid/src/main/java/com/suaro/pidroid/core/NativeMethods.java @@ -0,0 +1,15 @@ +package com.suaro.pidroid.core; + +import android.content.res.AssetManager; + +import org.jetbrains.annotations.NotNull; + + +public final class NativeMethods { + static { + System.loadLibrary("pidroid"); + } + public static native void setup(@NotNull PidroidConfig var1, @NotNull AssetManager var2); + + public static native void detectFace(@NotNull int[] var1, int var2, int var3, @NotNull FaceDetectionResult var4); +} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/NativeMethods.kt b/pidroid/src/main/java/com/suaro/pidroid/core/NativeMethods.kt deleted file mode 100644 index 81a5c66..0000000 --- a/pidroid/src/main/java/com/suaro/pidroid/core/NativeMethods.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.suaro.pidroid.core - -import android.content.res.AssetManager - - -class NativeMethods { - - companion object { - init { - System.loadLibrary("pidroid") - } - - external fun setup(config: PidroidConfig, mgr: AssetManager) - external fun detectFace(rgbaBytes: IntArray, width: Int, height: Int, detectionInfo: FaceDetectionResult) - } -} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.java b/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.java new file mode 100644 index 0000000..4ce29a7 --- /dev/null +++ b/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.java @@ -0,0 +1,103 @@ +package com.suaro.pidroid.core; + +public final class PidroidConfig { + private int minsize = 150; + private int maxsize = 1000; + private float scalefactor = 1.1F; + private float stridefactorWidth = 0.2F; + private float stridefactorHeight = 0.12F; + private float qthreshold = 1.0F; + private int perturbs = 10; + private boolean clustering = true; + private boolean pupilDetectionEnable = true; + private boolean landmarkDetectionEnable = true; + private boolean prominentFaceOnly; + + public int getMinsize() { + return minsize; + } + + public void setMinsize(int minsize) { + this.minsize = minsize; + } + + public int getMaxsize() { + return maxsize; + } + + public void setMaxsize(int maxsize) { + this.maxsize = maxsize; + } + + public float getScalefactor() { + return scalefactor; + } + + public void setScalefactor(float scalefactor) { + this.scalefactor = scalefactor; + } + + public float getStridefactorWidth() { + return stridefactorWidth; + } + + public void setStridefactorWidth(float stridefactorWidth) { + this.stridefactorWidth = stridefactorWidth; + } + + public float getStridefactorHeight() { + return stridefactorHeight; + } + + public void setStridefactorHeight(float stridefactorHeight) { + this.stridefactorHeight = stridefactorHeight; + } + + public float getQthreshold() { + return qthreshold; + } + + public void setQthreshold(float qthreshold) { + this.qthreshold = qthreshold; + } + + public int getPerturbs() { + return perturbs; + } + + public void setPerturbs(int perturbs) { + this.perturbs = perturbs; + } + + public boolean isClustering() { + return clustering; + } + + public void setClustering(boolean clustering) { + this.clustering = clustering; + } + + public boolean isPupilDetectionEnable() { + return pupilDetectionEnable; + } + + public void setPupilDetectionEnable(boolean pupilDetectionEnable) { + this.pupilDetectionEnable = pupilDetectionEnable; + } + + public boolean isLandmarkDetectionEnable() { + return landmarkDetectionEnable; + } + + public void setLandmarkDetectionEnable(boolean landmarkDetectionEnable) { + this.landmarkDetectionEnable = landmarkDetectionEnable; + } + + public boolean isProminentFaceOnly() { + return prominentFaceOnly; + } + + public void setProminentFaceOnly(boolean prominentFaceOnly) { + this.prominentFaceOnly = prominentFaceOnly; + } +} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.kt b/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.kt deleted file mode 100644 index 64e91f4..0000000 --- a/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.suaro.pidroid.core - -class PidroidConfig { - var minsize: Int = 150 - var maxsize: Int = 1000 - - // var angle: Float = 0f - - var scalefactor: Float = 1.1f - var stridefactorWidth: Float = 0.2f - var stridefactorHeight: Float = 0.12f - - var qthreshold: Float = 3.0f - - var perturbs: Int = 10; - - var clustering: Boolean = true - - var pupilDetectionEnable: Boolean = true - var landmarkDetectionEnable: Boolean = true - - var prominentFaceOnly: Boolean = false -} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/Point.java b/pidroid/src/main/java/com/suaro/pidroid/core/Point.java new file mode 100644 index 0000000..18ad978 --- /dev/null +++ b/pidroid/src/main/java/com/suaro/pidroid/core/Point.java @@ -0,0 +1,27 @@ +package com.suaro.pidroid.core; + +public final class Point { + private int x; + private int y; + + public final int getX() { + return this.x; + } + + public final void setX(int var1) { + this.x = var1; + } + + public final int getY() { + return this.y; + } + + public final void setY(int var1) { + this.y = var1; + } + + public Point(int x, int y) { + this.x = x; + this.y = y; + } +} \ No newline at end of file diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/Point.kt b/pidroid/src/main/java/com/suaro/pidroid/core/Point.kt deleted file mode 100644 index 557450d..0000000 --- a/pidroid/src/main/java/com/suaro/pidroid/core/Point.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.suaro.pidroid.core - -class Point constructor(var x: Int, var y: Int) { - -} \ No newline at end of file diff --git a/realtimesample/src/main/java/com/suaro/realtimesample/MainActivity.kt b/realtimesample/src/main/java/com/suaro/realtimesample/MainActivity.kt index 8b5ced0..2c156ae 100644 --- a/realtimesample/src/main/java/com/suaro/realtimesample/MainActivity.kt +++ b/realtimesample/src/main/java/com/suaro/realtimesample/MainActivity.kt @@ -39,6 +39,7 @@ class MainActivity : AppCompatActivity(), Camera.View, Capturer.View{ private fun setupNative() { val pidroidConfig = PidroidConfig() + pidroidConfig.isProminentFaceOnly = true Pidroid.setup(this, pidroidConfig) } From 521d279cf7d93744e0afc6126a42de5225412cb4 Mon Sep 17 00:00:00 2001 From: Suaro Date: Wed, 24 Mar 2021 23:17:53 +0100 Subject: [PATCH 2/4] Refactor image sample app to support API 16. Add default options to realtime app. --- README.md | 3 +-- .../src/main/java/com/suaro/imagesample/CanvasView.kt | 6 +++++- .../java/com/suaro/pidroid/core/PidroidConfig.java | 10 +++++----- .../main/java/com/suaro/realtimesample/MainActivity.kt | 3 ++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 483a247..cc60135 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/imagesample/src/main/java/com/suaro/imagesample/CanvasView.kt b/imagesample/src/main/java/com/suaro/imagesample/CanvasView.kt index ec3d4cf..397a749 100644 --- a/imagesample/src/main/java/com/suaro/imagesample/CanvasView.kt +++ b/imagesample/src/main/java/com/suaro/imagesample/CanvasView.kt @@ -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) {; diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.java b/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.java index 4ce29a7..6aec845 100644 --- a/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.java +++ b/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.java @@ -6,7 +6,7 @@ public final class PidroidConfig { private float scalefactor = 1.1F; private float stridefactorWidth = 0.2F; private float stridefactorHeight = 0.12F; - private float qthreshold = 1.0F; + private float qthreshold = 3.0F; private int perturbs = 10; private boolean clustering = true; private boolean pupilDetectionEnable = true; @@ -69,7 +69,7 @@ public void setPerturbs(int perturbs) { this.perturbs = perturbs; } - public boolean isClustering() { + public boolean getClustering() { return clustering; } @@ -77,7 +77,7 @@ public void setClustering(boolean clustering) { this.clustering = clustering; } - public boolean isPupilDetectionEnable() { + public boolean getPupilDetectionEnable() { return pupilDetectionEnable; } @@ -85,7 +85,7 @@ public void setPupilDetectionEnable(boolean pupilDetectionEnable) { this.pupilDetectionEnable = pupilDetectionEnable; } - public boolean isLandmarkDetectionEnable() { + public boolean getLandmarkDetectionEnable() { return landmarkDetectionEnable; } @@ -93,7 +93,7 @@ public void setLandmarkDetectionEnable(boolean landmarkDetectionEnable) { this.landmarkDetectionEnable = landmarkDetectionEnable; } - public boolean isProminentFaceOnly() { + public boolean getProminentFaceOnly() { return prominentFaceOnly; } diff --git a/realtimesample/src/main/java/com/suaro/realtimesample/MainActivity.kt b/realtimesample/src/main/java/com/suaro/realtimesample/MainActivity.kt index 2c156ae..154b814 100644 --- a/realtimesample/src/main/java/com/suaro/realtimesample/MainActivity.kt +++ b/realtimesample/src/main/java/com/suaro/realtimesample/MainActivity.kt @@ -39,7 +39,8 @@ class MainActivity : AppCompatActivity(), Camera.View, Capturer.View{ private fun setupNative() { val pidroidConfig = PidroidConfig() - pidroidConfig.isProminentFaceOnly = true + pidroidConfig.prominentFaceOnly = true + pidroidConfig.qthreshold = 1.5f Pidroid.setup(this, pidroidConfig) } From 4beb84c793c4d9353d50cdf8bebeb5655b012dfd Mon Sep 17 00:00:00 2001 From: Suaro Date: Wed, 24 Mar 2021 23:52:17 +0100 Subject: [PATCH 3/4] Update README and sample app. --- README.md | 6 +++--- .../com/suaro/imagesample/ImageActivity.kt | 19 +++++++++++-------- .../src/main/res/layout/activity_image.xml | 2 +- .../com/suaro/pidroid/core/PidroidConfig.java | 4 ++-- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index cc60135..9729947 100644 --- a/README.md +++ b/README.md @@ -155,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 | diff --git a/imagesample/src/main/java/com/suaro/imagesample/ImageActivity.kt b/imagesample/src/main/java/com/suaro/imagesample/ImageActivity.kt index e44bbf5..e9b88f4 100644 --- a/imagesample/src/main/java/com/suaro/imagesample/ImageActivity.kt +++ b/imagesample/src/main/java/com/suaro/imagesample/ImageActivity.kt @@ -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 } diff --git a/imagesample/src/main/res/layout/activity_image.xml b/imagesample/src/main/res/layout/activity_image.xml index 132ba51..a2e7f2b 100644 --- a/imagesample/src/main/res/layout/activity_image.xml +++ b/imagesample/src/main/res/layout/activity_image.xml @@ -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" diff --git a/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.java b/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.java index 6aec845..1c1f8b5 100644 --- a/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.java +++ b/pidroid/src/main/java/com/suaro/pidroid/core/PidroidConfig.java @@ -4,8 +4,8 @@ public final class PidroidConfig { private int minsize = 150; private int maxsize = 1000; private float scalefactor = 1.1F; - private float stridefactorWidth = 0.2F; - private float stridefactorHeight = 0.12F; + private float stridefactorWidth = 0.1F; + private float stridefactorHeight = 0.1F; private float qthreshold = 3.0F; private int perturbs = 10; private boolean clustering = true; From c2dc514305d51c487b04674b3d24a2d8de95f929 Mon Sep 17 00:00:00 2001 From: Suaro Date: Wed, 24 Mar 2021 23:53:41 +0100 Subject: [PATCH 4/4] Update versionCode to 2 Update versionName to 1.1 --- pidroid/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pidroid/build.gradle b/pidroid/build.gradle index bddd7ff..dc7df7a 100644 --- a/pidroid/build.gradle +++ b/pidroid/build.gradle @@ -9,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"