[Android] Add facedet Android app example (#614)

* [Backend] fix lite backend save model error

* [Backend] fixed typos

* [FlyCV] optimize the integration of FlyCV

* [cmake] close some tests options

* [cmake] close some test option

* [FlyCV] remove un-need warnings

* [FlyCV] remove un-need GetMat method

* [FlyCV] optimize FlyCV codes

* [cmake] remove un-need cmake function in examples/CMakelists

* [cmake] support gflags for Android

* [Android] Run button shutter in sub Ui Thread

* [Android] Update CameraSurfaceView

* [Android] Update Android SDK usage docs

* [Android] Add facedet Android app example
This commit is contained in:
DefTruth
2022-11-16 17:56:18 +08:00
committed by GitHub
parent a2b487765d
commit 606494a571
22 changed files with 1194 additions and 54 deletions

View File

@@ -57,7 +57,8 @@ Java_com_baidu_paddle_fastdeploy_vision_facedet_SCRFD_bindNative(
JNIEXPORT jobject JNICALL
Java_com_baidu_paddle_fastdeploy_vision_facedet_SCRFD_predictNative(
JNIEnv *env, jobject thiz, jlong cxx_context,
jobject argb8888_bitmap, jboolean save_image,
jobject argb8888_bitmap, jfloat conf_threshold,
jfloat nms_iou_threshold, jboolean save_image,
jstring save_path, jboolean rendering) {
if (cxx_context == 0) {
return NULL;
@@ -69,7 +70,7 @@ Java_com_baidu_paddle_fastdeploy_vision_facedet_SCRFD_predictNative(
auto c_model_ptr = reinterpret_cast<facedet::SCRFD *>(cxx_context);
vision::FaceDetectionResult c_result;
auto t = fni::GetCurrentTime();
c_model_ptr->Predict(&c_bgr, &c_result);
c_model_ptr->Predict(&c_bgr, &c_result, conf_threshold, nms_iou_threshold);
PERF_TIME_OF_RUNTIME(c_model_ptr, t)
if (rendering) {
fni::RenderingFaceDetection(env, c_bgr, c_result, argb8888_bitmap,

View File

@@ -57,7 +57,8 @@ Java_com_baidu_paddle_fastdeploy_vision_facedet_YOLOv5Face_bindNative(
JNIEXPORT jobject JNICALL
Java_com_baidu_paddle_fastdeploy_vision_facedet_YOLOv5Face_predictNative(
JNIEnv *env, jobject thiz, jlong cxx_context,
jobject argb8888_bitmap, jboolean save_image,
jobject argb8888_bitmap, jfloat conf_threshold,
jfloat nms_iou_threshold, jboolean save_image,
jstring save_path, jboolean rendering) {
if (cxx_context == 0) {
return NULL;
@@ -69,7 +70,7 @@ Java_com_baidu_paddle_fastdeploy_vision_facedet_YOLOv5Face_predictNative(
auto c_model_ptr = reinterpret_cast<facedet::YOLOv5Face *>(cxx_context);
vision::FaceDetectionResult c_result;
auto t = fni::GetCurrentTime();
c_model_ptr->Predict(&c_bgr, &c_result);
c_model_ptr->Predict(&c_bgr, &c_result, conf_threshold, nms_iou_threshold);
PERF_TIME_OF_RUNTIME(c_model_ptr, t)
if (rendering) {
fni::RenderingFaceDetection(env, c_bgr, c_result, argb8888_bitmap,

View File

@@ -54,7 +54,7 @@ public class SCRFD {
}
// Only support ARGB8888 bitmap in native now.
FaceDetectionResult result = predictNative(mCxxContext, ARGB8888Bitmap,
false, "", false);
0.25f, 0.4f, false, "", false);
if (result == null) {
return new FaceDetectionResult();
}
@@ -62,13 +62,30 @@ public class SCRFD {
}
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
boolean rendering) {
float confThreshold,
float nmsIouThreshold) {
if (mCxxContext == 0) {
return new FaceDetectionResult();
}
// Only support ARGB8888 bitmap in native now.
FaceDetectionResult result = predictNative(mCxxContext, ARGB8888Bitmap,
false, "", rendering);
confThreshold, nmsIouThreshold, false, "", false);
if (result == null) {
return new FaceDetectionResult();
}
return result;
}
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
boolean rendering,
float confThreshold,
float nmsIouThreshold) {
if (mCxxContext == 0) {
return new FaceDetectionResult();
}
// Only support ARGB8888 bitmap in native now.
FaceDetectionResult result = predictNative(mCxxContext, ARGB8888Bitmap,
confThreshold, nmsIouThreshold, false, "", rendering);
if (result == null) {
return new FaceDetectionResult();
}
@@ -77,15 +94,17 @@ public class SCRFD {
// Predict with image saving and bitmap rendering (will cost more times)
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
String savedImagePath) {
String savedImagePath,
float confThreshold,
float nmsIouThreshold) {
// scoreThreshold is for visualizing only.
if (mCxxContext == 0) {
return new FaceDetectionResult();
}
// Only support ARGB8888 bitmap in native now.
FaceDetectionResult result = predictNative(
mCxxContext, ARGB8888Bitmap, true,
savedImagePath, true);
mCxxContext, ARGB8888Bitmap, confThreshold, nmsIouThreshold,
true, savedImagePath, true);
if (result == null) {
return new FaceDetectionResult();
}
@@ -128,6 +147,8 @@ public class SCRFD {
// Call prediction from native context with rendering.
private native FaceDetectionResult predictNative(long CxxContext,
Bitmap ARGB8888Bitmap,
float confThreshold,
float nmsIouThreshold,
boolean saveImage,
String savePath,
boolean rendering);

View File

@@ -53,7 +53,7 @@ public class YOLOv5Face {
}
// Only support ARGB8888 bitmap in native now.
FaceDetectionResult result = predictNative(mCxxContext, ARGB8888Bitmap,
false, "", false);
0.25f, 0.4f, false, "", false);
if (result == null) {
return new FaceDetectionResult();
}
@@ -61,13 +61,30 @@ public class YOLOv5Face {
}
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
boolean rendering) {
float confThreshold,
float nmsIouThreshold) {
if (mCxxContext == 0) {
return new FaceDetectionResult();
}
// Only support ARGB8888 bitmap in native now.
FaceDetectionResult result = predictNative(mCxxContext, ARGB8888Bitmap,
false, "", rendering);
confThreshold, nmsIouThreshold, false, "", false);
if (result == null) {
return new FaceDetectionResult();
}
return result;
}
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
boolean rendering,
float confThreshold,
float nmsIouThreshold) {
if (mCxxContext == 0) {
return new FaceDetectionResult();
}
// Only support ARGB8888 bitmap in native now.
FaceDetectionResult result = predictNative(mCxxContext, ARGB8888Bitmap,
confThreshold, nmsIouThreshold, false, "", rendering);
if (result == null) {
return new FaceDetectionResult();
}
@@ -76,15 +93,17 @@ public class YOLOv5Face {
// Predict with image saving and bitmap rendering (will cost more times)
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
String savedImagePath) {
String savedImagePath,
float confThreshold,
float nmsIouThreshold) {
// scoreThreshold is for visualizing only.
if (mCxxContext == 0) {
return new FaceDetectionResult();
}
// Only support ARGB8888 bitmap in native now.
FaceDetectionResult result = predictNative(
mCxxContext, ARGB8888Bitmap, true,
savedImagePath, true);
mCxxContext, ARGB8888Bitmap, confThreshold, nmsIouThreshold,
true, savedImagePath, true);
if (result == null) {
return new FaceDetectionResult();
}
@@ -127,6 +146,8 @@ public class YOLOv5Face {
// Call prediction from native context with rendering.
private native FaceDetectionResult predictNative(long CxxContext,
Bitmap ARGB8888Bitmap,
float confThreshold,
float nmsIouThreshold,
boolean saveImage,
String savePath,
boolean rendering);