diff --git a/docs/en/build_and_install/download_prebuilt_libraries.md b/docs/en/build_and_install/download_prebuilt_libraries.md
index 58edd1d56e..99f4f5ea85 100755
--- a/docs/en/build_and_install/download_prebuilt_libraries.md
+++ b/docs/en/build_and_install/download_prebuilt_libraries.md
@@ -44,13 +44,13 @@ Install the released version(Latest 0.6.0)
| Platform | File | Description |
|:----------- |:--------------------------------------------------------------------------------------------------------------------- |:--------------------------------------------------------- |
| Linux x64 | [fastdeploy-linux-x64-gpu-0.6.0.tgz](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-gpu-0.6.0.tgz) | Compiled from g++ 8.2, CUDA 11.2, cuDNN 8.2 |
-| Windows x64 | [fastdeploy-win-x64-gpu-0.5.0.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-gpu-0.6.0.zip) | Compiled from Visual Studio 16 2019, CUDA 11.2, cuDNN 8.2 |
+| Windows x64 | [fastdeploy-win-x64-gpu-0.6.0.zip](https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-win-x64-gpu-0.6.0.zip) | Compiled from Visual Studio 16 2019, CUDA 11.2, cuDNN 8.2 |
Install the Develop version(Nightly build)
| Platform | File | Description |
|:----------- |:--------------------------------------------------------------------------------------------------------------------- |:--------------------------------------------------------- |
-| Linux x64 | [fastdeploy-linux-x64-gpu-0.0.0.tgz](https://fastdeploy.bj.bcebos.com/dev/cpp/fastdeploy-linux-x64-gpu-0.0.0.tgz | Compiled from g++ 8.2, CUDA 11.2, cuDNN 8.2 |
+| Linux x64 | [fastdeploy-linux-x64-gpu-0.0.0.tgz](https://fastdeploy.bj.bcebos.com/dev/cpp/fastdeploy-linux-x64-gpu-0.0.0.tgz) | Compiled from g++ 8.2, CUDA 11.2, cuDNN 8.2 |
| Windows x64 | [fastdeploy-win-x64-gpu-0.0.0.zip](https://fastdeploy.bj.bcebos.com/dev/cpp/fastdeploy-win-x64-gpu-0.0.0.zip) | Compiled from Visual Studio 16 2019, CUDA 11.2, cuDNN 8.2 |
## CPU Deployment Environment
@@ -93,7 +93,7 @@ Install the Develop version(Nightly build)
| Platform | File | Description |
|:------------- |:--------------------------------------------------------------------------------------------------------------------- |:------------------------------ |
-| Linux x64 | [fastdeploy-linux-x64-0.0.0.tgz](https://fastdeploy.bj.bcebos.com/dev/cpp/fastdeploy-linux-x64-0.0.0.tgz) | Compiled from g++ 8.2 |
+| Linux x64 | [fastdeploy-linux-x64-0.0.0.tgz](https://fastdeploy.bj.bcebos.com/dev/cpp/fastdeploy-linux-x64-0.0.0.tgz) | Compiled from g++ 8.2 |
| Windows x64 | [fastdeploy-win-x64-0.0.0.zip](https://fastdeploy.bj.bcebos.com/dev/cpp/fastdeploy-win-x64-0.0.0.zip) | Compiled from Visual Studio 16 |
| Mac OSX x64 | - | - |
| Mac OSX arm64 | [fastdeploy-osx-arm64-0.0.0.tgz](https://fastdeploy.bj.bcebos.com/dev/cpp/fastdeploy-osx-arm64-0.0.0.tgz) | - |
diff --git a/java/android/README.md b/java/android/README.md
index aae25b6800..e73443506f 100644
--- a/java/android/README.md
+++ b/java/android/README.md
@@ -188,9 +188,10 @@ public boolean init(String modelFile, String paramsFile, RuntimeOption option);
```java
// 直接预测:不保存图片以及不渲染结果到Bitmap上
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap);
+public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, float confThreshold, float nmsIouThreshold); // 设置置信度阈值和NMS阈值
// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上
-public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float scoreThreshold);
-public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float scoreThreshold); // 只渲染 不保存图片
+public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float confThreshold, float nmsIouThreshold);
+public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float confThreshold, float nmsIouThreshold); // 只渲染 不保存图片
```
- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。
```java
@@ -216,9 +217,10 @@ public boolean init(String modelFile, String paramsFile, RuntimeOption option);
```java
// 直接预测:不保存图片以及不渲染结果到Bitmap上
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap);
+public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, float confThreshold, float nmsIouThreshold); // 设置置信度阈值和NMS阈值
// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上
-public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float scoreThreshold);
-public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float scoreThreshold); // 只渲染 不保存图片
+public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float confThreshold, float nmsIouThreshold);
+public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float confThreshold, float nmsIouThreshold); // 只渲染 不保存图片
```
- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。
```java
diff --git a/java/android/app/src/main/AndroidManifest.xml b/java/android/app/src/main/AndroidManifest.xml
index 1cdc519e05..316b35c034 100644
--- a/java/android/app/src/main/AndroidManifest.xml
+++ b/java/android/app/src/main/AndroidManifest.xml
@@ -11,18 +11,18 @@
-
+
diff --git a/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/detection/DetectionMainActivity.java b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/detection/DetectionMainActivity.java
index 0b2ca905c7..2b654e8a8c 100644
--- a/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/detection/DetectionMainActivity.java
+++ b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/detection/DetectionMainActivity.java
@@ -1,8 +1,5 @@
package com.baidu.paddle.fastdeploy.app.examples.detection;
-import static com.baidu.paddle.fastdeploy.app.ui.Utils.decodeBitmap;
-import static com.baidu.paddle.fastdeploy.app.ui.Utils.getRealPathFromURI;
-
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
@@ -34,6 +31,7 @@ import android.widget.TextView;
import com.baidu.paddle.fastdeploy.RuntimeOption;
import com.baidu.paddle.fastdeploy.app.examples.R;
+import com.baidu.paddle.fastdeploy.app.examples.facedet.FaceDetMainActivity;
import com.baidu.paddle.fastdeploy.app.ui.view.CameraSurfaceView;
import com.baidu.paddle.fastdeploy.app.ui.view.ResultListView;
import com.baidu.paddle.fastdeploy.app.ui.Utils;
@@ -42,13 +40,14 @@ import com.baidu.paddle.fastdeploy.app.ui.view.model.BaseResultModel;
import com.baidu.paddle.fastdeploy.vision.DetectionResult;
import com.baidu.paddle.fastdeploy.vision.detection.PicoDet;
+import static com.baidu.paddle.fastdeploy.app.ui.Utils.decodeBitmap;
+import static com.baidu.paddle.fastdeploy.app.ui.Utils.getRealPathFromURI;
+
import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
-import javax.microedition.khronos.opengles.GL10;
-
public class DetectionMainActivity extends Activity implements View.OnClickListener, CameraSurfaceView.OnTextureChangedListener {
private static final String TAG = DetectionMainActivity.class.getSimpleName();
@@ -122,7 +121,7 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
break;
case R.id.btn_shutter:
TYPE = BTN_SHUTTER;
- runOnShutterUiThread();
+ shutterAndPauseCamera();
break;
case R.id.btn_settings:
startActivity(new Intent(DetectionMainActivity.this, DetectionSettingsActivity.class));
@@ -154,32 +153,39 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
}
}
- private void runOnShutterUiThread() {
- runOnUiThread(new Runnable() {
- @SuppressLint("SetTextI18n")
+ private void shutterAndPauseCamera() {
+ new Thread(new Runnable() {
+ @Override
public void run() {
try {
- Thread.sleep(TIME_SLEEP_INTERVAL * 2);
-
- svPreview.onPause();
- cameraPageView.setVisibility(View.GONE);
- resultPageView.setVisibility(View.VISIBLE);
- seekbarText.setText(resultNum + "");
- confidenceSeekbar.setProgress((int) (resultNum * 100));
- if (shutterBitmap != null && !shutterBitmap.isRecycled()) {
- resultImage.setImageBitmap(shutterBitmap);
- } else {
- new AlertDialog.Builder(DetectionMainActivity.this)
- .setTitle("Empty Result!")
- .setMessage("Current picture is empty, please shutting it again!")
- .setCancelable(true)
- .show();
- }
+ // Sleep some times to ensure picture has been correctly shut.
+ Thread.sleep(TIME_SLEEP_INTERVAL * 2); // 100ms
} catch (InterruptedException e) {
e.printStackTrace();
}
+ runOnUiThread(new Runnable() {
+ @SuppressLint("SetTextI18n")
+ public void run() {
+ // These code will run in main thread.
+ svPreview.onPause();
+ cameraPageView.setVisibility(View.GONE);
+ resultPageView.setVisibility(View.VISIBLE);
+ seekbarText.setText(resultNum + "");
+ confidenceSeekbar.setProgress((int) (resultNum * 100));
+ if (shutterBitmap != null && !shutterBitmap.isRecycled()) {
+ resultImage.setImageBitmap(shutterBitmap);
+ } else {
+ new AlertDialog.Builder(DetectionMainActivity.this)
+ .setTitle("Empty Result!")
+ .setMessage("Current picture is empty, please shutting it again!")
+ .setCancelable(true)
+ .show();
+ }
+ }
+ });
+
}
- });
+ }).start();
}
private void copyBitmapFromCamera(Bitmap ARGB8888ImageBitmap) {
@@ -191,6 +197,7 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
originShutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
}
+ SystemClock.sleep(TIME_SLEEP_INTERVAL); // 50ms
}
}
@@ -233,11 +240,9 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
@Override
public boolean onTextureChanged(Bitmap ARGB8888ImageBitmap) {
- synchronized (this) {
- if (TYPE == BTN_SHUTTER) {
- copyBitmapFromCamera(ARGB8888ImageBitmap);
- return false;
- }
+ if (TYPE == BTN_SHUTTER) {
+ copyBitmapFromCamera(ARGB8888ImageBitmap);
+ return false;
}
String savedImagePath = "";
diff --git a/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/facedet/FaceDetMainActivity.java b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/facedet/FaceDetMainActivity.java
new file mode 100644
index 0000000000..a5b5aa839d
--- /dev/null
+++ b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/facedet/FaceDetMainActivity.java
@@ -0,0 +1,465 @@
+package com.baidu.paddle.fastdeploy.app.examples.facedet;
+
+import android.Manifest;
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.SystemClock;
+import android.preference.PreferenceManager;
+import android.provider.MediaStore;
+import android.support.annotation.NonNull;
+import android.support.v4.app.ActivityCompat;
+import android.support.v4.content.ContextCompat;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.SeekBar;
+import android.widget.TextView;
+
+import com.baidu.paddle.fastdeploy.RuntimeOption;
+import com.baidu.paddle.fastdeploy.app.examples.R;
+import com.baidu.paddle.fastdeploy.app.ui.view.CameraSurfaceView;
+import com.baidu.paddle.fastdeploy.app.ui.view.ResultListView;
+import com.baidu.paddle.fastdeploy.app.ui.Utils;
+import com.baidu.paddle.fastdeploy.app.ui.view.adapter.BaseResultAdapter;
+import com.baidu.paddle.fastdeploy.app.ui.view.model.BaseResultModel;
+import com.baidu.paddle.fastdeploy.vision.DetectionResult;
+import com.baidu.paddle.fastdeploy.vision.FaceDetectionResult;
+import com.baidu.paddle.fastdeploy.vision.facedet.SCRFD;
+
+import static com.baidu.paddle.fastdeploy.app.ui.Utils.decodeBitmap;
+import static com.baidu.paddle.fastdeploy.app.ui.Utils.getRealPathFromURI;
+
+import java.io.File;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+public class FaceDetMainActivity extends Activity implements View.OnClickListener, CameraSurfaceView.OnTextureChangedListener {
+ private static final String TAG = FaceDetMainActivity.class.getSimpleName();
+
+ CameraSurfaceView svPreview;
+ TextView tvStatus;
+ ImageButton btnSwitch;
+ ImageButton btnShutter;
+ ImageButton btnSettings;
+ ImageView realtimeToggleButton;
+ boolean isRealtimeStatusRunning = false;
+ ImageView backInPreview;
+ private ImageView albumSelectButton;
+ private View cameraPageView;
+ private ViewGroup resultPageView;
+ private ImageView resultImage;
+ private ImageView backInResult;
+ private SeekBar confidenceSeekbar;
+ private TextView seekbarText;
+ private float resultConfThreshold = 1.0f;
+ private ResultListView detectResultView;
+ private Bitmap shutterBitmap;
+ private Bitmap originShutterBitmap;
+ private Bitmap picBitmap;
+ private Bitmap originPicBitmap;
+
+ public static final int TYPE_UNKNOWN = -1;
+ public static final int BTN_SHUTTER = 0;
+ public static final int ALBUM_SELECT = 1;
+ public static final int REALTIME_DETECT = 2;
+ private static int TYPE = REALTIME_DETECT;
+
+ private static final int REQUEST_PERMISSION_CODE_STORAGE = 101;
+ private static final int INTENT_CODE_PICK_IMAGE = 100;
+ private static final int TIME_SLEEP_INTERVAL = 50; // ms
+
+ String savedImagePath = "result.jpg";
+ int lastFrameIndex = 0;
+ long lastFrameTime;
+
+ // Call 'init' and 'release' manually later
+ SCRFD predictor = new SCRFD();
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // Fullscreen
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
+
+ setContentView(R.layout.facedet_activity_main);
+
+ // Clear all setting items to avoid app crashing due to the incorrect settings
+ initSettings();
+
+ // Init the camera preview and UI components
+ initView();
+
+ // Check and request CAMERA and WRITE_EXTERNAL_STORAGE permissions
+ if (!checkAllPermissions()) {
+ requestAllPermissions();
+ }
+ }
+
+ @SuppressLint("NonConstantResourceId")
+ @Override
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.btn_switch:
+ svPreview.switchCamera();
+ break;
+ case R.id.btn_shutter:
+ TYPE = BTN_SHUTTER;
+ shutterAndPauseCamera();
+ break;
+ case R.id.btn_settings:
+ startActivity(new Intent(FaceDetMainActivity.this, FaceDetSettingsActivity.class));
+ break;
+ case R.id.realtime_toggle_btn:
+ toggleRealtimeStyle();
+ break;
+ case R.id.back_in_preview:
+ finish();
+ break;
+ case R.id.album_select:
+ TYPE = ALBUM_SELECT;
+ // Judge whether authority has been granted.
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
+ // If this permission was requested before the application but the user refused the request, this method will return true.
+ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION_CODE_STORAGE);
+ } else {
+ Intent intent = new Intent(Intent.ACTION_PICK);
+ intent.setType("image/*");
+ startActivityForResult(intent, INTENT_CODE_PICK_IMAGE);
+ }
+ break;
+ case R.id.back_in_result:
+ resultPageView.setVisibility(View.GONE);
+ cameraPageView.setVisibility(View.VISIBLE);
+ TYPE = REALTIME_DETECT;
+ svPreview.onResume();
+ break;
+ }
+ }
+
+ private void shutterAndPauseCamera() {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ // Sleep some times to ensure picture has been correctly shut.
+ Thread.sleep(TIME_SLEEP_INTERVAL * 2); // 100ms
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ runOnUiThread(new Runnable() {
+ @SuppressLint("SetTextI18n")
+ public void run() {
+ // These codes will run in main thread.
+ svPreview.onPause();
+ cameraPageView.setVisibility(View.GONE);
+ resultPageView.setVisibility(View.VISIBLE);
+ seekbarText.setText(resultConfThreshold + "");
+ confidenceSeekbar.setProgress((int) (resultConfThreshold * 100));
+ if (shutterBitmap != null && !shutterBitmap.isRecycled()) {
+ resultImage.setImageBitmap(shutterBitmap);
+ } else {
+ new AlertDialog.Builder(FaceDetMainActivity.this)
+ .setTitle("Empty Result!")
+ .setMessage("Current picture is empty, please shutting it again!")
+ .setCancelable(true)
+ .show();
+ }
+ }
+ });
+
+ }
+ }).start();
+ }
+
+ private void copyBitmapFromCamera(Bitmap ARGB8888ImageBitmap) {
+ if (ARGB8888ImageBitmap == null) {
+ return;
+ }
+ if (!ARGB8888ImageBitmap.isRecycled()) {
+ synchronized (this) {
+ shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
+ originShutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
+ }
+ SystemClock.sleep(TIME_SLEEP_INTERVAL);
+ }
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == INTENT_CODE_PICK_IMAGE) {
+ if (resultCode == Activity.RESULT_OK) {
+ cameraPageView.setVisibility(View.GONE);
+ resultPageView.setVisibility(View.VISIBLE);
+ seekbarText.setText(resultConfThreshold + "");
+ confidenceSeekbar.setProgress((int) (resultConfThreshold * 100));
+ Uri uri = data.getData();
+ String path = getRealPathFromURI(this, uri);
+ picBitmap = decodeBitmap(path, 720, 1280);
+ originPicBitmap = picBitmap.copy(Bitmap.Config.ARGB_8888, true);
+ resultImage.setImageBitmap(picBitmap);
+ }
+ }
+ }
+
+ private void toggleRealtimeStyle() {
+ if (isRealtimeStatusRunning) {
+ isRealtimeStatusRunning = false;
+ realtimeToggleButton.setImageResource(R.drawable.realtime_stop_btn);
+ svPreview.setOnTextureChangedListener(this);
+ tvStatus.setVisibility(View.VISIBLE);
+ } else {
+ isRealtimeStatusRunning = true;
+ realtimeToggleButton.setImageResource(R.drawable.realtime_start_btn);
+ tvStatus.setVisibility(View.GONE);
+ svPreview.setOnTextureChangedListener(new CameraSurfaceView.OnTextureChangedListener() {
+ @Override
+ public boolean onTextureChanged(Bitmap ARGB8888ImageBitmap) {
+ return false;
+ }
+ });
+ }
+ }
+
+ @Override
+ public boolean onTextureChanged(Bitmap ARGB8888ImageBitmap) {
+ if (TYPE == BTN_SHUTTER) {
+ copyBitmapFromCamera(ARGB8888ImageBitmap);
+ return false;
+ }
+
+ String savedImagePath = "";
+ synchronized (this) {
+ savedImagePath = Utils.getDCIMDirectory() + File.separator + "result.jpg";
+ }
+
+ boolean modified = false;
+ FaceDetectionResult result = predictor.predict(
+ ARGB8888ImageBitmap, true, FaceDetSettingsActivity.scoreThreshold, 0.4f);
+ modified = result.initialized();
+ if (!savedImagePath.isEmpty()) {
+ synchronized (this) {
+ FaceDetMainActivity.this.savedImagePath = "result.jpg";
+ }
+ }
+ lastFrameIndex++;
+ if (lastFrameIndex >= 30) {
+ final int fps = (int) (lastFrameIndex * 1e9 / (System.nanoTime() - lastFrameTime));
+ runOnUiThread(new Runnable() {
+ @SuppressLint("SetTextI18n")
+ public void run() {
+ tvStatus.setText(Integer.toString(fps) + "fps");
+ }
+ });
+ lastFrameIndex = 0;
+ lastFrameTime = System.nanoTime();
+ }
+ return modified;
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ // Reload settings and re-initialize the predictor
+ checkAndUpdateSettings();
+ // Open camera until the permissions have been granted
+ if (!checkAllPermissions()) {
+ svPreview.disableCamera();
+ }
+ svPreview.onResume();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ svPreview.onPause();
+ }
+
+ @Override
+ protected void onDestroy() {
+ if (predictor != null) {
+ predictor.release();
+ }
+ super.onDestroy();
+ }
+
+ public void initView() {
+ TYPE = REALTIME_DETECT;
+ svPreview = (CameraSurfaceView) findViewById(R.id.sv_preview);
+ svPreview.setOnTextureChangedListener(this);
+ tvStatus = (TextView) findViewById(R.id.tv_status);
+ btnSwitch = (ImageButton) findViewById(R.id.btn_switch);
+ btnSwitch.setOnClickListener(this);
+ btnShutter = (ImageButton) findViewById(R.id.btn_shutter);
+ btnShutter.setOnClickListener(this);
+ btnSettings = (ImageButton) findViewById(R.id.btn_settings);
+ btnSettings.setOnClickListener(this);
+ realtimeToggleButton = findViewById(R.id.realtime_toggle_btn);
+ realtimeToggleButton.setOnClickListener(this);
+ backInPreview = findViewById(R.id.back_in_preview);
+ backInPreview.setOnClickListener(this);
+ albumSelectButton = findViewById(R.id.album_select);
+ albumSelectButton.setOnClickListener(this);
+ cameraPageView = findViewById(R.id.camera_page);
+ resultPageView = findViewById(R.id.result_page);
+ resultImage = findViewById(R.id.result_image);
+ backInResult = findViewById(R.id.back_in_result);
+ backInResult.setOnClickListener(this);
+ confidenceSeekbar = findViewById(R.id.confidence_seekbar);
+ seekbarText = findViewById(R.id.seekbar_text);
+ detectResultView = findViewById(R.id.result_list_view);
+
+ List results = new ArrayList<>();
+ // TODO: add model results from FaceDetectionResult instead of using fake data.
+ results.add(new BaseResultModel(1, "face", 0.4f));
+ results.add(new BaseResultModel(2, "face", 0.6f));
+ results.add(new BaseResultModel(3, "face", 1.0f));
+ final BaseResultAdapter adapter = new BaseResultAdapter(this, R.layout.facedet_result_page_item, results);
+ detectResultView.setAdapter(adapter);
+ detectResultView.invalidate();
+
+ confidenceSeekbar.setMax(100);
+ confidenceSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ float resultConfidence = seekBar.getProgress() / 100f;
+ BigDecimal bd = new BigDecimal(resultConfidence);
+ resultConfThreshold = bd.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
+ seekbarText.setText(resultConfThreshold + "");
+ confidenceSeekbar.setProgress((int) (resultConfThreshold * 100));
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (TYPE == ALBUM_SELECT) {
+ SystemClock.sleep(TIME_SLEEP_INTERVAL * 10); // 500ms
+ if (!picBitmap.isRecycled()) {
+ predictor.predict(picBitmap, true, resultConfThreshold, 0.4f);
+ resultImage.setImageBitmap(picBitmap);
+ picBitmap = originPicBitmap.copy(Bitmap.Config.ARGB_8888, true);
+ }
+ resultConfThreshold = 1.0f;
+ } else {
+ SystemClock.sleep(TIME_SLEEP_INTERVAL * 10); // 500ms
+ if (!shutterBitmap.isRecycled()) {
+ predictor.predict(shutterBitmap, true, resultConfThreshold, 0.4f);
+ resultImage.setImageBitmap(shutterBitmap);
+ shutterBitmap = originShutterBitmap.copy(Bitmap.Config.ARGB_8888, true);
+ }
+ resultConfThreshold = 1.0f;
+ }
+ }
+ });
+ }
+ });
+ }
+
+ @SuppressLint("ApplySharedPref")
+ public void initSettings() {
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ editor.clear();
+ editor.commit();
+ FaceDetSettingsActivity.resetSettings();
+ }
+
+ public void checkAndUpdateSettings() {
+ if (FaceDetSettingsActivity.checkAndUpdateSettings(this)) {
+ String realModelDir = getCacheDir() + "/" + FaceDetSettingsActivity.modelDir;
+ Utils.copyDirectoryFromAssets(this, FaceDetSettingsActivity.modelDir, realModelDir);
+
+ String modelFile = realModelDir + "/" + "model.pdmodel";
+ String paramsFile = realModelDir + "/" + "model.pdiparams";
+ RuntimeOption option = new RuntimeOption();
+ option.setCpuThreadNum(FaceDetSettingsActivity.cpuThreadNum);
+ option.setLitePowerMode(FaceDetSettingsActivity.cpuPowerMode);
+ if (Boolean.parseBoolean(FaceDetSettingsActivity.enableLiteFp16)) {
+ option.enableLiteFp16();
+ }
+ predictor.init(modelFile, paramsFile, option);
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
+ @NonNull int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ if (grantResults[0] != PackageManager.PERMISSION_GRANTED || grantResults[1] != PackageManager.PERMISSION_GRANTED) {
+ new AlertDialog.Builder(FaceDetMainActivity.this)
+ .setTitle("Permission denied")
+ .setMessage("Click to force quit the app, then open Settings->Apps & notifications->Target " +
+ "App->Permissions to grant all of the permissions.")
+ .setCancelable(false)
+ .setPositiveButton("Exit", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ FaceDetMainActivity.this.finish();
+ }
+ }).show();
+ }
+ }
+
+ private void requestAllPermissions() {
+ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
+ Manifest.permission.CAMERA}, 0);
+ }
+
+ private boolean checkAllPermissions() {
+ return ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
+ && ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/facedet/FaceDetSettingsActivity.java b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/facedet/FaceDetSettingsActivity.java
new file mode 100644
index 0000000000..ed82c5b59f
--- /dev/null
+++ b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/facedet/FaceDetSettingsActivity.java
@@ -0,0 +1,181 @@
+package com.baidu.paddle.fastdeploy.app.examples.facedet;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.EditTextPreference;
+import android.preference.ListPreference;
+import android.preference.PreferenceManager;
+import android.support.v7.app.ActionBar;
+
+import com.baidu.paddle.fastdeploy.app.examples.R;
+import com.baidu.paddle.fastdeploy.app.ui.Utils;
+import com.baidu.paddle.fastdeploy.app.ui.view.AppCompatPreferenceActivity;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class FaceDetSettingsActivity extends AppCompatPreferenceActivity implements
+ SharedPreferences.OnSharedPreferenceChangeListener {
+ private static final String TAG = FaceDetSettingsActivity.class.getSimpleName();
+
+ static public int selectedModelIdx = -1;
+ static public String modelDir = "";
+ static public int cpuThreadNum = 2;
+ static public String cpuPowerMode = "";
+ static public float scoreThreshold = 0.25f;
+ static public String enableLiteFp16 = "true";
+
+ ListPreference lpChoosePreInstalledModel = null;
+ EditTextPreference etModelDir = null;
+ ListPreference lpCPUThreadNum = null;
+ ListPreference lpCPUPowerMode = null;
+ EditTextPreference etScoreThreshold = null;
+ ListPreference lpEnableLiteFp16 = null;
+
+ List preInstalledModelDirs = null;
+ List preInstalledCPUThreadNums = null;
+ List preInstalledCPUPowerModes = null;
+ List preInstalledScoreThresholds = null;
+ List preInstalledEnableLiteFp16s = null;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.facedet_setting);
+ ActionBar supportActionBar = getSupportActionBar();
+ if (supportActionBar != null) {
+ supportActionBar.setDisplayHomeAsUpEnabled(true);
+ }
+
+ // Initialize pre-installed models
+ preInstalledModelDirs = new ArrayList();
+ preInstalledCPUThreadNums = new ArrayList();
+ preInstalledCPUPowerModes = new ArrayList();
+ preInstalledScoreThresholds = new ArrayList();
+ preInstalledEnableLiteFp16s = new ArrayList();
+ preInstalledModelDirs.add(getString(R.string.FACEDET_MODEL_DIR_DEFAULT));
+ preInstalledCPUThreadNums.add(getString(R.string.CPU_THREAD_NUM_DEFAULT));
+ preInstalledCPUPowerModes.add(getString(R.string.CPU_POWER_MODE_DEFAULT));
+ preInstalledScoreThresholds.add(getString(R.string.SCORE_THRESHOLD_FACEDET));
+ preInstalledEnableLiteFp16s.add(getString(R.string.ENABLE_LITE_FP16_MODE_DEFAULT));
+
+ // Setup UI components
+ lpChoosePreInstalledModel =
+ (ListPreference) findPreference(getString(R.string.CHOOSE_PRE_INSTALLED_MODEL_KEY));
+ String[] preInstalledModelNames = new String[preInstalledModelDirs.size()];
+ for (int i = 0; i < preInstalledModelDirs.size(); i++) {
+ preInstalledModelNames[i] = preInstalledModelDirs.get(i).substring(preInstalledModelDirs.get(i).lastIndexOf("/") + 1);
+ }
+ lpChoosePreInstalledModel.setEntries(preInstalledModelNames);
+ lpChoosePreInstalledModel.setEntryValues(preInstalledModelDirs.toArray(new String[preInstalledModelDirs.size()]));
+ lpCPUThreadNum = (ListPreference) findPreference(getString(R.string.CPU_THREAD_NUM_KEY));
+ lpCPUPowerMode = (ListPreference) findPreference(getString(R.string.CPU_POWER_MODE_KEY));
+ etModelDir = (EditTextPreference) findPreference(getString(R.string.MODEL_DIR_KEY));
+ etModelDir.setTitle("Model dir (SDCard: " + Utils.getSDCardDirectory() + ")");
+ etScoreThreshold = (EditTextPreference) findPreference(getString(R.string.SCORE_THRESHOLD_KEY));
+ lpEnableLiteFp16 = (ListPreference) findPreference(getString(R.string.ENABLE_LITE_FP16_MODE_KEY));
+ }
+
+ @SuppressLint("ApplySharedPref")
+ private void reloadSettingsAndUpdateUI() {
+ SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
+
+ String selected_model_dir = sharedPreferences.getString(getString(R.string.CHOOSE_PRE_INSTALLED_MODEL_KEY),
+ getString(R.string.FACEDET_MODEL_DIR_DEFAULT));
+ int selected_model_idx = lpChoosePreInstalledModel.findIndexOfValue(selected_model_dir);
+ if (selected_model_idx >= 0 && selected_model_idx < preInstalledModelDirs.size() && selected_model_idx != selectedModelIdx) {
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ editor.putString(getString(R.string.MODEL_DIR_KEY), preInstalledModelDirs.get(selected_model_idx));
+ editor.putString(getString(R.string.CPU_THREAD_NUM_KEY), preInstalledCPUThreadNums.get(selected_model_idx));
+ editor.putString(getString(R.string.CPU_POWER_MODE_KEY), preInstalledCPUPowerModes.get(selected_model_idx));
+ editor.putString(getString(R.string.SCORE_THRESHOLD_KEY), preInstalledScoreThresholds.get(selected_model_idx));
+ editor.putString(getString(R.string.ENABLE_LITE_FP16_MODE_DEFAULT), preInstalledEnableLiteFp16s.get(selected_model_idx));
+ editor.commit();
+ lpChoosePreInstalledModel.setSummary(selected_model_dir);
+ selectedModelIdx = selected_model_idx;
+ }
+
+ String model_dir = sharedPreferences.getString(getString(R.string.MODEL_DIR_KEY),
+ getString(R.string.FACEDET_MODEL_DIR_DEFAULT));
+ String cpu_thread_num = sharedPreferences.getString(getString(R.string.CPU_THREAD_NUM_KEY),
+ getString(R.string.CPU_THREAD_NUM_DEFAULT));
+ String cpu_power_mode = sharedPreferences.getString(getString(R.string.CPU_POWER_MODE_KEY),
+ getString(R.string.CPU_POWER_MODE_DEFAULT));
+ String score_threshold = sharedPreferences.getString(getString(R.string.SCORE_THRESHOLD_KEY),
+ getString(R.string.SCORE_THRESHOLD_FACEDET));
+ String enable_lite_fp16 = sharedPreferences.getString(getString(R.string.ENABLE_LITE_FP16_MODE_KEY),
+ getString(R.string.ENABLE_LITE_FP16_MODE_DEFAULT));
+
+ etModelDir.setSummary(model_dir);
+ lpCPUThreadNum.setValue(cpu_thread_num);
+ lpCPUThreadNum.setSummary(cpu_thread_num);
+ lpCPUPowerMode.setValue(cpu_power_mode);
+ lpCPUPowerMode.setSummary(cpu_power_mode);
+ etScoreThreshold.setSummary(score_threshold);
+ etScoreThreshold.setText(score_threshold);
+ lpEnableLiteFp16.setValue(enable_lite_fp16);
+ lpEnableLiteFp16.setSummary(enable_lite_fp16);
+
+ }
+
+ static boolean checkAndUpdateSettings(Context ctx) {
+ boolean settingsChanged = false;
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx);
+
+ String model_dir = sharedPreferences.getString(ctx.getString(R.string.MODEL_DIR_KEY),
+ ctx.getString(R.string.FACEDET_MODEL_DIR_DEFAULT));
+ settingsChanged |= !modelDir.equalsIgnoreCase(model_dir);
+ modelDir = model_dir;
+
+ String cpu_thread_num = sharedPreferences.getString(ctx.getString(R.string.CPU_THREAD_NUM_KEY),
+ ctx.getString(R.string.CPU_THREAD_NUM_DEFAULT));
+ settingsChanged |= cpuThreadNum != Integer.parseInt(cpu_thread_num);
+ cpuThreadNum = Integer.parseInt(cpu_thread_num);
+
+ String cpu_power_mode = sharedPreferences.getString(ctx.getString(R.string.CPU_POWER_MODE_KEY),
+ ctx.getString(R.string.CPU_POWER_MODE_DEFAULT));
+ settingsChanged |= !cpuPowerMode.equalsIgnoreCase(cpu_power_mode);
+ cpuPowerMode = cpu_power_mode;
+
+ String score_threshold = sharedPreferences.getString(ctx.getString(R.string.SCORE_THRESHOLD_KEY),
+ ctx.getString(R.string.SCORE_THRESHOLD_FACEDET));
+ settingsChanged |= scoreThreshold != Float.parseFloat(score_threshold);
+ scoreThreshold = Float.parseFloat(score_threshold);
+
+ String enable_lite_fp16 = sharedPreferences.getString(ctx.getString(R.string.ENABLE_LITE_FP16_MODE_KEY),
+ ctx.getString(R.string.ENABLE_LITE_FP16_MODE_DEFAULT));
+ settingsChanged |= !enableLiteFp16.equalsIgnoreCase(enable_lite_fp16);
+ enableLiteFp16 = enable_lite_fp16;
+
+ return settingsChanged;
+ }
+
+ static void resetSettings() {
+ selectedModelIdx = -1;
+ modelDir = "";
+ cpuThreadNum = 2;
+ cpuPowerMode = "";
+ scoreThreshold = 0.25f; // confThreshold
+ enableLiteFp16 = "true";
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
+ reloadSettingsAndUpdateUI();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ reloadSettingsAndUpdateUI();
+ }
+}
diff --git a/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/segmentation/SegmentationMainActivity.java b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/segmentation/SegmentationMainActivity.java
new file mode 100644
index 0000000000..1b6f28774f
--- /dev/null
+++ b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/segmentation/SegmentationMainActivity.java
@@ -0,0 +1,4 @@
+package com.baidu.paddle.fastdeploy.app.examples.segmentation;
+
+public class SegmentationMainActivity {
+}
diff --git a/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/segmentation/SegmentationSettingsActivity.java b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/segmentation/SegmentationSettingsActivity.java
new file mode 100644
index 0000000000..1cbc0f5cca
--- /dev/null
+++ b/java/android/app/src/main/java/com/baidu/paddle/fastdeploy/app/examples/segmentation/SegmentationSettingsActivity.java
@@ -0,0 +1,4 @@
+package com.baidu.paddle.fastdeploy.app.examples.segmentation;
+
+public class SegmentationSettingsActivity {
+}
diff --git a/java/android/app/src/main/res/layout/facedet_activity_main.xml b/java/android/app/src/main/res/layout/facedet_activity_main.xml
new file mode 100644
index 0000000000..51b548df4e
--- /dev/null
+++ b/java/android/app/src/main/res/layout/facedet_activity_main.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
diff --git a/java/android/app/src/main/res/layout/facedet_camera_page.xml b/java/android/app/src/main/res/layout/facedet_camera_page.xml
new file mode 100644
index 0000000000..f6b43ad0b5
--- /dev/null
+++ b/java/android/app/src/main/res/layout/facedet_camera_page.xml
@@ -0,0 +1,159 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/java/android/app/src/main/res/layout/facedet_result_page.xml b/java/android/app/src/main/res/layout/facedet_result_page.xml
new file mode 100644
index 0000000000..958a859401
--- /dev/null
+++ b/java/android/app/src/main/res/layout/facedet_result_page.xml
@@ -0,0 +1,160 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/java/android/app/src/main/res/layout/facedet_result_page_item.xml b/java/android/app/src/main/res/layout/facedet_result_page_item.xml
new file mode 100644
index 0000000000..6a2b09ebff
--- /dev/null
+++ b/java/android/app/src/main/res/layout/facedet_result_page_item.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/java/android/app/src/main/res/layout/segmentation_activity_main.xml b/java/android/app/src/main/res/layout/segmentation_activity_main.xml
new file mode 100644
index 0000000000..ae843ab710
--- /dev/null
+++ b/java/android/app/src/main/res/layout/segmentation_activity_main.xml
@@ -0,0 +1,6 @@
+
+
+
+
\ No newline at end of file
diff --git a/java/android/app/src/main/res/layout/segmentation_camera_page.xml b/java/android/app/src/main/res/layout/segmentation_camera_page.xml
new file mode 100644
index 0000000000..ae843ab710
--- /dev/null
+++ b/java/android/app/src/main/res/layout/segmentation_camera_page.xml
@@ -0,0 +1,6 @@
+
+
+
+
\ No newline at end of file
diff --git a/java/android/app/src/main/res/layout/segmentation_result_page.xml b/java/android/app/src/main/res/layout/segmentation_result_page.xml
new file mode 100644
index 0000000000..ae843ab710
--- /dev/null
+++ b/java/android/app/src/main/res/layout/segmentation_result_page.xml
@@ -0,0 +1,6 @@
+
+
+
+
\ No newline at end of file
diff --git a/java/android/app/src/main/res/layout/segmentation_result_page_item.xml b/java/android/app/src/main/res/layout/segmentation_result_page_item.xml
new file mode 100644
index 0000000000..ae843ab710
--- /dev/null
+++ b/java/android/app/src/main/res/layout/segmentation_result_page_item.xml
@@ -0,0 +1,6 @@
+
+
+
+
\ No newline at end of file
diff --git a/java/android/app/src/main/res/values/strings.xml b/java/android/app/src/main/res/values/strings.xml
index 9ae5341db3..b5f9cd2e8a 100644
--- a/java/android/app/src/main/res/values/strings.xml
+++ b/java/android/app/src/main/res/values/strings.xml
@@ -5,6 +5,8 @@
EasyEdge
EasyEdge
EasyEdge
+ EasyEdge
+ EasyEdge
CHOOSE_INSTALLED_MODEL_KEY
MODEL_DIR_KEY
@@ -18,6 +20,7 @@
LITE_POWER_HIGH
0.4
0.1
+ 0.25
true
@@ -29,6 +32,10 @@
models/MobileNetV1_x0_25_infer
labels/imagenet1k_label_list.txt
+
+ models/scrfd_500m_bnkps_shape320x320_pd
+
+ models/Portrait_PP_HumanSegV2_Lite_256x144_infer
拍照识别
实时识别
diff --git a/java/android/app/src/main/res/xml/facedet_setting.xml b/java/android/app/src/main/res/xml/facedet_setting.xml
new file mode 100644
index 0000000000..cab7f937a9
--- /dev/null
+++ b/java/android/app/src/main/res/xml/facedet_setting.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/java/android/app/src/main/res/xml/segmentation_setting.xml b/java/android/app/src/main/res/xml/segmentation_setting.xml
new file mode 100644
index 0000000000..624ed13aec
--- /dev/null
+++ b/java/android/app/src/main/res/xml/segmentation_setting.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/java/android/fastdeploy/src/main/cpp/fastdeploy_jni/vision/facedet/scrfd_jni.cc b/java/android/fastdeploy/src/main/cpp/fastdeploy_jni/vision/facedet/scrfd_jni.cc
index f45e554569..b1b313bf13 100644
--- a/java/android/fastdeploy/src/main/cpp/fastdeploy_jni/vision/facedet/scrfd_jni.cc
+++ b/java/android/fastdeploy/src/main/cpp/fastdeploy_jni/vision/facedet/scrfd_jni.cc
@@ -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(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,
diff --git a/java/android/fastdeploy/src/main/cpp/fastdeploy_jni/vision/facedet/yolov5face_jni.cc b/java/android/fastdeploy/src/main/cpp/fastdeploy_jni/vision/facedet/yolov5face_jni.cc
index c764728ea5..e08db0c9a9 100644
--- a/java/android/fastdeploy/src/main/cpp/fastdeploy_jni/vision/facedet/yolov5face_jni.cc
+++ b/java/android/fastdeploy/src/main/cpp/fastdeploy_jni/vision/facedet/yolov5face_jni.cc
@@ -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(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,
diff --git a/java/android/fastdeploy/src/main/java/com/baidu/paddle/fastdeploy/vision/facedet/SCRFD.java b/java/android/fastdeploy/src/main/java/com/baidu/paddle/fastdeploy/vision/facedet/SCRFD.java
index 7a042133db..200ddaf950 100644
--- a/java/android/fastdeploy/src/main/java/com/baidu/paddle/fastdeploy/vision/facedet/SCRFD.java
+++ b/java/android/fastdeploy/src/main/java/com/baidu/paddle/fastdeploy/vision/facedet/SCRFD.java
@@ -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);
diff --git a/java/android/fastdeploy/src/main/java/com/baidu/paddle/fastdeploy/vision/facedet/YOLOv5Face.java b/java/android/fastdeploy/src/main/java/com/baidu/paddle/fastdeploy/vision/facedet/YOLOv5Face.java
index 49464c8686..3446f82cd1 100644
--- a/java/android/fastdeploy/src/main/java/com/baidu/paddle/fastdeploy/vision/facedet/YOLOv5Face.java
+++ b/java/android/fastdeploy/src/main/java/com/baidu/paddle/fastdeploy/vision/facedet/YOLOv5Face.java
@@ -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);