mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-11 19:40:25 +08:00
[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:
@@ -188,9 +188,10 @@ public boolean init(String modelFile, String paramsFile, RuntimeOption option);
|
|||||||
```java
|
```java
|
||||||
// 直接预测:不保存图片以及不渲染结果到Bitmap上
|
// 直接预测:不保存图片以及不渲染结果到Bitmap上
|
||||||
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap);
|
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap);
|
||||||
|
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, float confThreshold, float nmsIouThreshold); // 设置置信度阈值和NMS阈值
|
||||||
// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上
|
// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上
|
||||||
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float scoreThreshold);
|
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float confThreshold, float nmsIouThreshold);
|
||||||
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float scoreThreshold); // 只渲染 不保存图片
|
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float confThreshold, float nmsIouThreshold); // 只渲染 不保存图片
|
||||||
```
|
```
|
||||||
- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。
|
- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。
|
||||||
```java
|
```java
|
||||||
@@ -216,9 +217,10 @@ public boolean init(String modelFile, String paramsFile, RuntimeOption option);
|
|||||||
```java
|
```java
|
||||||
// 直接预测:不保存图片以及不渲染结果到Bitmap上
|
// 直接预测:不保存图片以及不渲染结果到Bitmap上
|
||||||
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap);
|
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap);
|
||||||
|
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, float confThreshold, float nmsIouThreshold); // 设置置信度阈值和NMS阈值
|
||||||
// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上
|
// 预测并且可视化:预测结果以及可视化,并将可视化后的图片保存到指定的途径,以及将可视化结果渲染在Bitmap上
|
||||||
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float scoreThreshold);
|
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, String savedImagePath, float confThreshold, float nmsIouThreshold);
|
||||||
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float scoreThreshold); // 只渲染 不保存图片
|
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap, boolean rendering, float confThreshold, float nmsIouThreshold); // 只渲染 不保存图片
|
||||||
```
|
```
|
||||||
- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。
|
- 模型资源释放 API:调用 release() API 可以释放模型资源,返回true表示释放成功,false表示失败;调用 initialized() 可以判断模型是否初始化成功,true表示初始化成功,false表示失败。
|
||||||
```java
|
```java
|
||||||
|
@@ -11,18 +11,18 @@
|
|||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/detection_app_name"
|
android:label="@string/facedet_app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
<activity android:name=".detection.DetectionMainActivity">
|
<activity android:name=".facedet.FaceDetMainActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".detection.DetectionSettingsActivity"
|
android:name=".facedet.FaceDetSettingsActivity"
|
||||||
android:label="Settings">
|
android:label="Settings">
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
@@ -1,8 +1,5 @@
|
|||||||
package com.baidu.paddle.fastdeploy.app.examples.detection;
|
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.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@@ -34,6 +31,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.baidu.paddle.fastdeploy.RuntimeOption;
|
import com.baidu.paddle.fastdeploy.RuntimeOption;
|
||||||
import com.baidu.paddle.fastdeploy.app.examples.R;
|
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.CameraSurfaceView;
|
||||||
import com.baidu.paddle.fastdeploy.app.ui.view.ResultListView;
|
import com.baidu.paddle.fastdeploy.app.ui.view.ResultListView;
|
||||||
import com.baidu.paddle.fastdeploy.app.ui.Utils;
|
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.DetectionResult;
|
||||||
import com.baidu.paddle.fastdeploy.vision.detection.PicoDet;
|
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.io.File;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.microedition.khronos.opengles.GL10;
|
|
||||||
|
|
||||||
public class DetectionMainActivity extends Activity implements View.OnClickListener, CameraSurfaceView.OnTextureChangedListener {
|
public class DetectionMainActivity extends Activity implements View.OnClickListener, CameraSurfaceView.OnTextureChangedListener {
|
||||||
private static final String TAG = DetectionMainActivity.class.getSimpleName();
|
private static final String TAG = DetectionMainActivity.class.getSimpleName();
|
||||||
|
|
||||||
@@ -122,7 +121,7 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
break;
|
break;
|
||||||
case R.id.btn_shutter:
|
case R.id.btn_shutter:
|
||||||
TYPE = BTN_SHUTTER;
|
TYPE = BTN_SHUTTER;
|
||||||
runOnShutterUiThread();
|
shutterAndPauseCamera();
|
||||||
break;
|
break;
|
||||||
case R.id.btn_settings:
|
case R.id.btn_settings:
|
||||||
startActivity(new Intent(DetectionMainActivity.this, DetectionSettingsActivity.class));
|
startActivity(new Intent(DetectionMainActivity.this, DetectionSettingsActivity.class));
|
||||||
@@ -154,13 +153,20 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runOnShutterUiThread() {
|
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() {
|
runOnUiThread(new Runnable() {
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
// These code will run in main thread.
|
||||||
Thread.sleep(TIME_SLEEP_INTERVAL * 2);
|
|
||||||
|
|
||||||
svPreview.onPause();
|
svPreview.onPause();
|
||||||
cameraPageView.setVisibility(View.GONE);
|
cameraPageView.setVisibility(View.GONE);
|
||||||
resultPageView.setVisibility(View.VISIBLE);
|
resultPageView.setVisibility(View.VISIBLE);
|
||||||
@@ -175,11 +181,11 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyBitmapFromCamera(Bitmap ARGB8888ImageBitmap) {
|
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);
|
shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||||
originShutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
originShutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||||
}
|
}
|
||||||
|
SystemClock.sleep(TIME_SLEEP_INTERVAL); // 50ms
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,12 +240,10 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTextureChanged(Bitmap ARGB8888ImageBitmap) {
|
public boolean onTextureChanged(Bitmap ARGB8888ImageBitmap) {
|
||||||
synchronized (this) {
|
|
||||||
if (TYPE == BTN_SHUTTER) {
|
if (TYPE == BTN_SHUTTER) {
|
||||||
copyBitmapFromCamera(ARGB8888ImageBitmap);
|
copyBitmapFromCamera(ARGB8888ImageBitmap);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
String savedImagePath = "";
|
String savedImagePath = "";
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
@@ -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<BaseResultModel> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@@ -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<String> preInstalledModelDirs = null;
|
||||||
|
List<String> preInstalledCPUThreadNums = null;
|
||||||
|
List<String> preInstalledCPUPowerModes = null;
|
||||||
|
List<String> preInstalledScoreThresholds = null;
|
||||||
|
List<String> 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<String>();
|
||||||
|
preInstalledCPUThreadNums = new ArrayList<String>();
|
||||||
|
preInstalledCPUPowerModes = new ArrayList<String>();
|
||||||
|
preInstalledScoreThresholds = new ArrayList<String>();
|
||||||
|
preInstalledEnableLiteFp16s = new ArrayList<String>();
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,4 @@
|
|||||||
|
package com.baidu.paddle.fastdeploy.app.examples.segmentation;
|
||||||
|
|
||||||
|
public class SegmentationMainActivity {
|
||||||
|
}
|
@@ -0,0 +1,4 @@
|
|||||||
|
package com.baidu.paddle.fastdeploy.app.examples.segmentation;
|
||||||
|
|
||||||
|
public class SegmentationSettingsActivity {
|
||||||
|
}
|
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/facedet_camera_page"
|
||||||
|
android:id="@+id/camera_page"></include>
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/facedet_result_page"
|
||||||
|
android:id="@+id/result_page"
|
||||||
|
android:visibility="gone"></include>
|
||||||
|
</FrameLayout>
|
159
java/android/app/src/main/res/layout/facedet_camera_page.xml
Normal file
159
java/android/app/src/main/res/layout/facedet_camera_page.xml
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:keepScreenOn="true"
|
||||||
|
tools:context=".facedet.FaceDetMainActivity">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/colorWindow">
|
||||||
|
|
||||||
|
<com.baidu.paddle.fastdeploy.app.ui.layout.ActionBarLayout
|
||||||
|
android:id="@+id/action_bar_main"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/back_in_preview"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:cropToPadding="true"
|
||||||
|
android:paddingLeft="40px"
|
||||||
|
android:paddingTop="60px"
|
||||||
|
android:paddingRight="60px"
|
||||||
|
android:paddingBottom="40px"
|
||||||
|
android:src="@drawable/back_btn" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="50px"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/action_takepicture_btn"
|
||||||
|
style="@style/action_btn_selected"
|
||||||
|
android:layout_width="300px"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/action_bar_take_photo"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/action_realtime_btn"
|
||||||
|
style="@style/action_btn"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/action_bar_realtime"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.baidu.paddle.fastdeploy.app.ui.view.CameraSurfaceView
|
||||||
|
android:id="@+id/sv_preview"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_above="@+id/contral"
|
||||||
|
android:layout_below="@+id/action_bar_main"
|
||||||
|
android:layout_centerInParent="true" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/album_select"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
|
android:layout_marginBottom="145dp"
|
||||||
|
android:background="@drawable/album_btn"
|
||||||
|
android:scaleType="fitXY" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_status"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_marginTop="60dp"
|
||||||
|
android:layout_marginRight="30dp"
|
||||||
|
android:textColor="@color/colorText"
|
||||||
|
android:textSize="@dimen/small_font_size" />
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/top_bar_height"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:background="@color/colorTopBar">
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/btn_settings"
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:background="@null"
|
||||||
|
android:scaleType="fitXY"
|
||||||
|
android:src="@drawable/btn_settings" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/contral"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:background="@color/colorBottomBar"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/bottom_bar_top_margin"
|
||||||
|
android:orientation="vertical"></LinearLayout>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/large_button_height">
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/btn_switch"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="60dp"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginLeft="60dp"
|
||||||
|
android:background="#00000000"
|
||||||
|
android:scaleType="fitXY"
|
||||||
|
android:src="@drawable/switch_side_btn" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/btn_shutter"
|
||||||
|
android:layout_width="@dimen/large_button_width"
|
||||||
|
android:layout_height="@dimen/large_button_height"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:background="@null"
|
||||||
|
android:scaleType="fitXY"
|
||||||
|
android:src="@drawable/take_picture_btn" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/realtime_toggle_btn"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="60dp"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginRight="60dp"
|
||||||
|
android:scaleType="fitXY"
|
||||||
|
android:src="@drawable/realtime_stop_btn" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/bottom_bar_bottom_margin"
|
||||||
|
android:orientation="vertical"></LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
</RelativeLayout>
|
||||||
|
</android.support.constraint.ConstraintLayout>
|
160
java/android/app/src/main/res/layout/facedet_result_page.xml
Normal file
160
java/android/app/src/main/res/layout/facedet_result_page.xml
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="#FFFFFF"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<com.baidu.paddle.fastdeploy.app.ui.layout.ActionBarLayout
|
||||||
|
android:id="@+id/action_bar_result"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/back_in_result"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:cropToPadding="true"
|
||||||
|
android:paddingLeft="40px"
|
||||||
|
android:paddingTop="60px"
|
||||||
|
android:paddingRight="60px"
|
||||||
|
android:paddingBottom="40px"
|
||||||
|
android:src="@drawable/back_btn" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/model_name"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="50px"
|
||||||
|
android:textColor="@color/textColor"
|
||||||
|
android:textSize="@dimen/action_btn_text_size" />
|
||||||
|
</com.baidu.paddle.fastdeploy.app.ui.layout.ActionBarLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="700px">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/result_image"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/bk_result_image_padding" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="40px"
|
||||||
|
android:layout_marginTop="26px"
|
||||||
|
android:layout_marginBottom="20px"
|
||||||
|
android:text="@string/result_label"
|
||||||
|
android:textColor="@color/bk_black"
|
||||||
|
android:textSize="56px"
|
||||||
|
android:visibility="visible" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/result_seekbar_section"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="130px"
|
||||||
|
android:layout_marginLeft="@dimen/result_list_padding_lr"
|
||||||
|
android:layout_marginRight="@dimen/result_list_padding_lr"
|
||||||
|
android:layout_marginBottom="@dimen/result_list_gap_width"
|
||||||
|
android:background="@drawable/result_page_border_section_bk"
|
||||||
|
android:visibility="visible">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="2"
|
||||||
|
android:paddingLeft="30px"
|
||||||
|
android:text="@string/result_table_header_confidence"
|
||||||
|
android:textColor="@color/table_result_tableheader_text_color"
|
||||||
|
android:textSize="@dimen/result_list_view_text_size" />
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/confidence_seekbar"
|
||||||
|
android:layout_width="220dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="6"
|
||||||
|
android:focusable="false"
|
||||||
|
android:maxHeight="8px"
|
||||||
|
android:progressDrawable="@drawable/seekbar_progress_result"
|
||||||
|
android:splitTrack="false"
|
||||||
|
android:thumb="@drawable/seekbar_handle" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/seekbar_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:paddingRight="30px"
|
||||||
|
android:textSize="@dimen/result_list_view_text_size"
|
||||||
|
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="@dimen/result_list_padding_lr"
|
||||||
|
android:layout_marginRight="@dimen/result_list_padding_lr"
|
||||||
|
android:layout_marginBottom="@dimen/result_list_gap_width"
|
||||||
|
android:background="@drawable/result_page_border_section_bk"
|
||||||
|
android:visibility="visible">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/list_result_view_tablehead_style"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/result_table_header_index"
|
||||||
|
android:textColor="@color/table_result_tableheader_text_color" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/list_result_view_tablehead_style"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/result_table_header_name"
|
||||||
|
android:textColor="@color/table_result_tableheader_text_color" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/list_result_view_tablehead_style"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0.4"
|
||||||
|
android:gravity="right"
|
||||||
|
android:text="@string/result_table_header_confidence"
|
||||||
|
android:textColor="@color/table_result_tableheader_text_color" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="15px"
|
||||||
|
android:paddingLeft="@dimen/result_list_padding_lr"
|
||||||
|
android:paddingRight="@dimen/result_list_padding_lr">
|
||||||
|
|
||||||
|
<com.baidu.paddle.fastdeploy.app.ui.view.ResultListView
|
||||||
|
android:id="@+id/result_list_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="700px"
|
||||||
|
android:divider="#FFFFFF"
|
||||||
|
android:dividerHeight="@dimen/result_list_gap_width"></com.baidu.paddle.fastdeploy.app.ui.view.ResultListView>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
</FrameLayout>
|
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/result_page_border_section_bk">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/index"
|
||||||
|
style="@style/list_result_view_item_style"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_weight="0.2" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/name"
|
||||||
|
style="@style/list_result_view_item_style"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_weight="0.6"
|
||||||
|
android:maxWidth="300px" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/confidence"
|
||||||
|
style="@style/list_result_view_item_style"
|
||||||
|
android:layout_weight="0.2"
|
||||||
|
android:layout_width="wrap_content" />
|
||||||
|
</LinearLayout>
|
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
</android.support.constraint.ConstraintLayout>
|
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
</android.support.constraint.ConstraintLayout>
|
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
</android.support.constraint.ConstraintLayout>
|
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
</android.support.constraint.ConstraintLayout>
|
@@ -5,6 +5,8 @@
|
|||||||
<string name="detection_app_name">EasyEdge</string>
|
<string name="detection_app_name">EasyEdge</string>
|
||||||
<string name="ocr_app_name">EasyEdge</string>
|
<string name="ocr_app_name">EasyEdge</string>
|
||||||
<string name="classification_app_name">EasyEdge</string>
|
<string name="classification_app_name">EasyEdge</string>
|
||||||
|
<string name="facedet_app_name">EasyEdge</string>
|
||||||
|
<string name="segmentation_app_name">EasyEdge</string>
|
||||||
<!-- Keys for PreferenceScreen -->
|
<!-- Keys for PreferenceScreen -->
|
||||||
<string name="CHOOSE_PRE_INSTALLED_MODEL_KEY">CHOOSE_INSTALLED_MODEL_KEY</string>
|
<string name="CHOOSE_PRE_INSTALLED_MODEL_KEY">CHOOSE_INSTALLED_MODEL_KEY</string>
|
||||||
<string name="MODEL_DIR_KEY">MODEL_DIR_KEY</string>
|
<string name="MODEL_DIR_KEY">MODEL_DIR_KEY</string>
|
||||||
@@ -18,6 +20,7 @@
|
|||||||
<string name="CPU_POWER_MODE_DEFAULT">LITE_POWER_HIGH</string>
|
<string name="CPU_POWER_MODE_DEFAULT">LITE_POWER_HIGH</string>
|
||||||
<string name="SCORE_THRESHOLD_DEFAULT">0.4</string>
|
<string name="SCORE_THRESHOLD_DEFAULT">0.4</string>
|
||||||
<string name="SCORE_THRESHOLD_CLASSIFICATION">0.1</string>
|
<string name="SCORE_THRESHOLD_CLASSIFICATION">0.1</string>
|
||||||
|
<string name="SCORE_THRESHOLD_FACEDET">0.25</string>
|
||||||
<string name="ENABLE_LITE_FP16_MODE_DEFAULT">true</string>
|
<string name="ENABLE_LITE_FP16_MODE_DEFAULT">true</string>
|
||||||
<!--Other values-->
|
<!--Other values-->
|
||||||
<!-- Detection model & Label paths & other values ... -->
|
<!-- Detection model & Label paths & other values ... -->
|
||||||
@@ -29,6 +32,10 @@
|
|||||||
<!-- classification values ... -->
|
<!-- classification values ... -->
|
||||||
<string name="CLASSIFICATION_MODEL_DIR_DEFAULT">models/MobileNetV1_x0_25_infer</string>
|
<string name="CLASSIFICATION_MODEL_DIR_DEFAULT">models/MobileNetV1_x0_25_infer</string>
|
||||||
<string name="CLASSIFICATION_LABEL_PATH_DEFAULT">labels/imagenet1k_label_list.txt</string>
|
<string name="CLASSIFICATION_LABEL_PATH_DEFAULT">labels/imagenet1k_label_list.txt</string>
|
||||||
|
<!-- facedet values ... -->
|
||||||
|
<string name="FACEDET_MODEL_DIR_DEFAULT">models/scrfd_500m_bnkps_shape320x320_pd</string>
|
||||||
|
<!-- segmentation values ... -->
|
||||||
|
<string name="SEGMENTATION_MODEL_DIR_DEFAULT">models/Portrait_PP_HumanSegV2_Lite_256x144_infer</string>
|
||||||
<!-- Other resources values-->
|
<!-- Other resources values-->
|
||||||
<string name="action_bar_take_photo">拍照识别</string>
|
<string name="action_bar_take_photo">拍照识别</string>
|
||||||
<string name="action_bar_realtime">实时识别</string>
|
<string name="action_bar_realtime">实时识别</string>
|
||||||
|
41
java/android/app/src/main/res/xml/facedet_setting.xml
Normal file
41
java/android/app/src/main/res/xml/facedet_setting.xml
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="@string/FACEDET_MODEL_DIR_DEFAULT"
|
||||||
|
android:key="@string/CHOOSE_PRE_INSTALLED_MODEL_KEY"
|
||||||
|
android:negativeButtonText="@null"
|
||||||
|
android:positiveButtonText="@null"
|
||||||
|
android:title="Choose Pre-Installed Models" />
|
||||||
|
<EditTextPreference
|
||||||
|
android:defaultValue="@string/FACEDET_MODEL_DIR_DEFAULT"
|
||||||
|
android:key="@string/MODEL_DIR_KEY"
|
||||||
|
android:title="Model Dir" />
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="@string/CPU_THREAD_NUM_DEFAULT"
|
||||||
|
android:entries="@array/cpu_thread_num_entries"
|
||||||
|
android:entryValues="@array/cpu_thread_num_values"
|
||||||
|
android:key="@string/CPU_THREAD_NUM_KEY"
|
||||||
|
android:negativeButtonText="@null"
|
||||||
|
android:positiveButtonText="@null"
|
||||||
|
android:title="CPU Thread Num" />
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="@string/CPU_POWER_MODE_DEFAULT"
|
||||||
|
android:entries="@array/cpu_power_mode_entries"
|
||||||
|
android:entryValues="@array/cpu_power_mode_values"
|
||||||
|
android:key="@string/CPU_POWER_MODE_KEY"
|
||||||
|
android:negativeButtonText="@null"
|
||||||
|
android:positiveButtonText="@null"
|
||||||
|
android:title="CPU Power Mode" />
|
||||||
|
<EditTextPreference
|
||||||
|
android:key="@string/SCORE_THRESHOLD_KEY"
|
||||||
|
android:defaultValue="@string/SCORE_THRESHOLD_DEFAULT"
|
||||||
|
android:title="Score Threshold: (0.0, 1.0)" />
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="@string/ENABLE_LITE_FP16_MODE_DEFAULT"
|
||||||
|
android:entries="@array/enable_lite_fp16_mode_entries"
|
||||||
|
android:entryValues="@array/enable_lite_fp16_mode_values"
|
||||||
|
android:key="@string/ENABLE_LITE_FP16_MODE_KEY"
|
||||||
|
android:negativeButtonText="@null"
|
||||||
|
android:positiveButtonText="@null"
|
||||||
|
android:title="Enable Lite FP16" />
|
||||||
|
</PreferenceScreen>
|
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@@ -57,7 +57,8 @@ Java_com_baidu_paddle_fastdeploy_vision_facedet_SCRFD_bindNative(
|
|||||||
JNIEXPORT jobject JNICALL
|
JNIEXPORT jobject JNICALL
|
||||||
Java_com_baidu_paddle_fastdeploy_vision_facedet_SCRFD_predictNative(
|
Java_com_baidu_paddle_fastdeploy_vision_facedet_SCRFD_predictNative(
|
||||||
JNIEnv *env, jobject thiz, jlong cxx_context,
|
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) {
|
jstring save_path, jboolean rendering) {
|
||||||
if (cxx_context == 0) {
|
if (cxx_context == 0) {
|
||||||
return NULL;
|
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);
|
auto c_model_ptr = reinterpret_cast<facedet::SCRFD *>(cxx_context);
|
||||||
vision::FaceDetectionResult c_result;
|
vision::FaceDetectionResult c_result;
|
||||||
auto t = fni::GetCurrentTime();
|
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)
|
PERF_TIME_OF_RUNTIME(c_model_ptr, t)
|
||||||
if (rendering) {
|
if (rendering) {
|
||||||
fni::RenderingFaceDetection(env, c_bgr, c_result, argb8888_bitmap,
|
fni::RenderingFaceDetection(env, c_bgr, c_result, argb8888_bitmap,
|
||||||
|
@@ -57,7 +57,8 @@ Java_com_baidu_paddle_fastdeploy_vision_facedet_YOLOv5Face_bindNative(
|
|||||||
JNIEXPORT jobject JNICALL
|
JNIEXPORT jobject JNICALL
|
||||||
Java_com_baidu_paddle_fastdeploy_vision_facedet_YOLOv5Face_predictNative(
|
Java_com_baidu_paddle_fastdeploy_vision_facedet_YOLOv5Face_predictNative(
|
||||||
JNIEnv *env, jobject thiz, jlong cxx_context,
|
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) {
|
jstring save_path, jboolean rendering) {
|
||||||
if (cxx_context == 0) {
|
if (cxx_context == 0) {
|
||||||
return NULL;
|
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);
|
auto c_model_ptr = reinterpret_cast<facedet::YOLOv5Face *>(cxx_context);
|
||||||
vision::FaceDetectionResult c_result;
|
vision::FaceDetectionResult c_result;
|
||||||
auto t = fni::GetCurrentTime();
|
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)
|
PERF_TIME_OF_RUNTIME(c_model_ptr, t)
|
||||||
if (rendering) {
|
if (rendering) {
|
||||||
fni::RenderingFaceDetection(env, c_bgr, c_result, argb8888_bitmap,
|
fni::RenderingFaceDetection(env, c_bgr, c_result, argb8888_bitmap,
|
||||||
|
@@ -54,7 +54,7 @@ public class SCRFD {
|
|||||||
}
|
}
|
||||||
// Only support ARGB8888 bitmap in native now.
|
// Only support ARGB8888 bitmap in native now.
|
||||||
FaceDetectionResult result = predictNative(mCxxContext, ARGB8888Bitmap,
|
FaceDetectionResult result = predictNative(mCxxContext, ARGB8888Bitmap,
|
||||||
false, "", false);
|
0.25f, 0.4f, false, "", false);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return new FaceDetectionResult();
|
return new FaceDetectionResult();
|
||||||
}
|
}
|
||||||
@@ -62,13 +62,30 @@ public class SCRFD {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
|
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
|
||||||
boolean rendering) {
|
float confThreshold,
|
||||||
|
float nmsIouThreshold) {
|
||||||
if (mCxxContext == 0) {
|
if (mCxxContext == 0) {
|
||||||
return new FaceDetectionResult();
|
return new FaceDetectionResult();
|
||||||
}
|
}
|
||||||
// Only support ARGB8888 bitmap in native now.
|
// Only support ARGB8888 bitmap in native now.
|
||||||
FaceDetectionResult result = predictNative(mCxxContext, ARGB8888Bitmap,
|
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) {
|
if (result == null) {
|
||||||
return new FaceDetectionResult();
|
return new FaceDetectionResult();
|
||||||
}
|
}
|
||||||
@@ -77,15 +94,17 @@ public class SCRFD {
|
|||||||
|
|
||||||
// Predict with image saving and bitmap rendering (will cost more times)
|
// Predict with image saving and bitmap rendering (will cost more times)
|
||||||
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
|
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
|
||||||
String savedImagePath) {
|
String savedImagePath,
|
||||||
|
float confThreshold,
|
||||||
|
float nmsIouThreshold) {
|
||||||
// scoreThreshold is for visualizing only.
|
// scoreThreshold is for visualizing only.
|
||||||
if (mCxxContext == 0) {
|
if (mCxxContext == 0) {
|
||||||
return new FaceDetectionResult();
|
return new FaceDetectionResult();
|
||||||
}
|
}
|
||||||
// Only support ARGB8888 bitmap in native now.
|
// Only support ARGB8888 bitmap in native now.
|
||||||
FaceDetectionResult result = predictNative(
|
FaceDetectionResult result = predictNative(
|
||||||
mCxxContext, ARGB8888Bitmap, true,
|
mCxxContext, ARGB8888Bitmap, confThreshold, nmsIouThreshold,
|
||||||
savedImagePath, true);
|
true, savedImagePath, true);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return new FaceDetectionResult();
|
return new FaceDetectionResult();
|
||||||
}
|
}
|
||||||
@@ -128,6 +147,8 @@ public class SCRFD {
|
|||||||
// Call prediction from native context with rendering.
|
// Call prediction from native context with rendering.
|
||||||
private native FaceDetectionResult predictNative(long CxxContext,
|
private native FaceDetectionResult predictNative(long CxxContext,
|
||||||
Bitmap ARGB8888Bitmap,
|
Bitmap ARGB8888Bitmap,
|
||||||
|
float confThreshold,
|
||||||
|
float nmsIouThreshold,
|
||||||
boolean saveImage,
|
boolean saveImage,
|
||||||
String savePath,
|
String savePath,
|
||||||
boolean rendering);
|
boolean rendering);
|
||||||
|
@@ -53,7 +53,7 @@ public class YOLOv5Face {
|
|||||||
}
|
}
|
||||||
// Only support ARGB8888 bitmap in native now.
|
// Only support ARGB8888 bitmap in native now.
|
||||||
FaceDetectionResult result = predictNative(mCxxContext, ARGB8888Bitmap,
|
FaceDetectionResult result = predictNative(mCxxContext, ARGB8888Bitmap,
|
||||||
false, "", false);
|
0.25f, 0.4f, false, "", false);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return new FaceDetectionResult();
|
return new FaceDetectionResult();
|
||||||
}
|
}
|
||||||
@@ -61,13 +61,30 @@ public class YOLOv5Face {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
|
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
|
||||||
boolean rendering) {
|
float confThreshold,
|
||||||
|
float nmsIouThreshold) {
|
||||||
if (mCxxContext == 0) {
|
if (mCxxContext == 0) {
|
||||||
return new FaceDetectionResult();
|
return new FaceDetectionResult();
|
||||||
}
|
}
|
||||||
// Only support ARGB8888 bitmap in native now.
|
// Only support ARGB8888 bitmap in native now.
|
||||||
FaceDetectionResult result = predictNative(mCxxContext, ARGB8888Bitmap,
|
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) {
|
if (result == null) {
|
||||||
return new FaceDetectionResult();
|
return new FaceDetectionResult();
|
||||||
}
|
}
|
||||||
@@ -76,15 +93,17 @@ public class YOLOv5Face {
|
|||||||
|
|
||||||
// Predict with image saving and bitmap rendering (will cost more times)
|
// Predict with image saving and bitmap rendering (will cost more times)
|
||||||
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
|
public FaceDetectionResult predict(Bitmap ARGB8888Bitmap,
|
||||||
String savedImagePath) {
|
String savedImagePath,
|
||||||
|
float confThreshold,
|
||||||
|
float nmsIouThreshold) {
|
||||||
// scoreThreshold is for visualizing only.
|
// scoreThreshold is for visualizing only.
|
||||||
if (mCxxContext == 0) {
|
if (mCxxContext == 0) {
|
||||||
return new FaceDetectionResult();
|
return new FaceDetectionResult();
|
||||||
}
|
}
|
||||||
// Only support ARGB8888 bitmap in native now.
|
// Only support ARGB8888 bitmap in native now.
|
||||||
FaceDetectionResult result = predictNative(
|
FaceDetectionResult result = predictNative(
|
||||||
mCxxContext, ARGB8888Bitmap, true,
|
mCxxContext, ARGB8888Bitmap, confThreshold, nmsIouThreshold,
|
||||||
savedImagePath, true);
|
true, savedImagePath, true);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return new FaceDetectionResult();
|
return new FaceDetectionResult();
|
||||||
}
|
}
|
||||||
@@ -127,6 +146,8 @@ public class YOLOv5Face {
|
|||||||
// Call prediction from native context with rendering.
|
// Call prediction from native context with rendering.
|
||||||
private native FaceDetectionResult predictNative(long CxxContext,
|
private native FaceDetectionResult predictNative(long CxxContext,
|
||||||
Bitmap ARGB8888Bitmap,
|
Bitmap ARGB8888Bitmap,
|
||||||
|
float confThreshold,
|
||||||
|
float nmsIouThreshold,
|
||||||
boolean saveImage,
|
boolean saveImage,
|
||||||
String savePath,
|
String savePath,
|
||||||
boolean rendering);
|
boolean rendering);
|
||||||
|
Reference in New Issue
Block a user