mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 00:33:03 +08:00
[Android] Add classification app examples (#590)
* 1.Classification Code submission; 2.Specification code format. * Specification code format. * Update strings.xml Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com>
This commit is contained in:
1000
java/android/app/src/main/assets/labels/imagenet1k_label_list.txt
Normal file
1000
java/android/app/src/main/assets/labels/imagenet1k_label_list.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,387 @@
|
|||||||
|
package com.baidu.paddle.fastdeploy.app.examples.classification;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
|
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.ClassifyResult;
|
||||||
|
import com.baidu.paddle.fastdeploy.vision.classification.PaddleClasModel;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ClassificationMainActivity extends Activity implements View.OnClickListener, CameraSurfaceView.OnTextureChangedListener {
|
||||||
|
private static final String TAG = ClassificationMainActivity.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 resultNum = 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;
|
||||||
|
private static int TYPE = TYPE_UNKNOWN;
|
||||||
|
|
||||||
|
private static final int REQUEST_PERMISSION_CODE_STORAGE = 101;
|
||||||
|
private static final int INTENT_CODE_PICK_IMAGE = 100;
|
||||||
|
|
||||||
|
String savedImagePath = "result.jpg";
|
||||||
|
int lastFrameIndex = 0;
|
||||||
|
long lastFrameTime;
|
||||||
|
|
||||||
|
// Call 'init' and 'release' manually later
|
||||||
|
PaddleClasModel predictor = new PaddleClasModel();
|
||||||
|
|
||||||
|
@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.classification_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;
|
||||||
|
svPreview.onPause();
|
||||||
|
cameraPageView.setVisibility(View.GONE);
|
||||||
|
resultPageView.setVisibility(View.VISIBLE);
|
||||||
|
seekbarText.setText(resultNum + "");
|
||||||
|
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
||||||
|
resultImage.setImageBitmap(shutterBitmap);
|
||||||
|
break;
|
||||||
|
case R.id.btn_settings:
|
||||||
|
startActivity(new Intent(ClassificationMainActivity.this, ClassificationSettingsActivity.class));
|
||||||
|
break;
|
||||||
|
case R.id.realtime_toggle_btn:
|
||||||
|
toggleRealtimeStyle();
|
||||||
|
break;
|
||||||
|
case R.id.back_in_preview:
|
||||||
|
finish();
|
||||||
|
break;
|
||||||
|
case R.id.albumSelect:
|
||||||
|
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);
|
||||||
|
svPreview.onResume();
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(resultNum + "");
|
||||||
|
confidenceSeekbar.setProgress((int) (resultNum * 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) {
|
||||||
|
String savedImagePath = "";
|
||||||
|
synchronized (this) {
|
||||||
|
savedImagePath = Utils.getDCIMDirectory() + File.separator + "result.jpg";
|
||||||
|
}
|
||||||
|
if (TYPE == BTN_SHUTTER) {
|
||||||
|
shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||||
|
originShutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||||
|
} else {
|
||||||
|
// Only reference in predict loops.
|
||||||
|
shutterBitmap = ARGB8888ImageBitmap;
|
||||||
|
originShutterBitmap = ARGB8888ImageBitmap;
|
||||||
|
}
|
||||||
|
boolean modified = false;
|
||||||
|
ClassifyResult result = predictor.predict(
|
||||||
|
ARGB8888ImageBitmap, true, ClassificationSettingsActivity.scoreThreshold);
|
||||||
|
modified = result.initialized();
|
||||||
|
if (!savedImagePath.isEmpty()) {
|
||||||
|
synchronized (this) {
|
||||||
|
ClassificationMainActivity.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 = BTN_SHUTTER;
|
||||||
|
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.albumSelect);
|
||||||
|
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<>();
|
||||||
|
results.add(new BaseResultModel(1, "cup", 0.4f));
|
||||||
|
results.add(new BaseResultModel(2, "pen", 0.6f));
|
||||||
|
results.add(new BaseResultModel(3, "tang", 1.0f));
|
||||||
|
final BaseResultAdapter adapter = new BaseResultAdapter(this, R.layout.classification_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);
|
||||||
|
resultNum = bd.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
|
||||||
|
seekbarText.setText(resultNum + "");
|
||||||
|
confidenceSeekbar.setProgress((int) (resultNum * 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(500);
|
||||||
|
predictor.predict(picBitmap, savedImagePath, resultNum);
|
||||||
|
resultImage.setImageBitmap(picBitmap);
|
||||||
|
picBitmap = originPicBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||||
|
resultNum = 1.0f;
|
||||||
|
} else {
|
||||||
|
SystemClock.sleep(500);
|
||||||
|
predictor.predict(shutterBitmap, savedImagePath, resultNum);
|
||||||
|
resultImage.setImageBitmap(shutterBitmap);
|
||||||
|
shutterBitmap = originShutterBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||||
|
resultNum = 1.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ApplySharedPref")
|
||||||
|
public void initSettings() {
|
||||||
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||||
|
editor.clear();
|
||||||
|
editor.commit();
|
||||||
|
ClassificationSettingsActivity.resetSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkAndUpdateSettings() {
|
||||||
|
if (ClassificationSettingsActivity.checkAndUpdateSettings(this)) {
|
||||||
|
String realModelDir = getCacheDir() + "/" + ClassificationSettingsActivity.modelDir;
|
||||||
|
Utils.copyDirectoryFromAssets(this, ClassificationSettingsActivity.modelDir, realModelDir);
|
||||||
|
String realLabelPath = getCacheDir() + "/" + ClassificationSettingsActivity.labelPath;
|
||||||
|
Utils.copyFileFromAssets(this, ClassificationSettingsActivity.labelPath, realLabelPath);
|
||||||
|
|
||||||
|
String modelFile = realModelDir + "/" + "inference.pdmodel";
|
||||||
|
String paramsFile = realModelDir + "/" + "inference.pdiparams";
|
||||||
|
String configFile = realModelDir + "/" + "inference_cls.yaml";
|
||||||
|
String labelFile = realLabelPath;
|
||||||
|
RuntimeOption option = new RuntimeOption();
|
||||||
|
option.setCpuThreadNum(ClassificationSettingsActivity.cpuThreadNum);
|
||||||
|
option.setLitePowerMode(ClassificationSettingsActivity.cpuPowerMode);
|
||||||
|
if (Boolean.parseBoolean(ClassificationSettingsActivity.enableLiteFp16)) {
|
||||||
|
option.enableLiteFp16();
|
||||||
|
}
|
||||||
|
predictor.init(modelFile, paramsFile, configFile, labelFile, 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(ClassificationMainActivity.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) {
|
||||||
|
ClassificationMainActivity.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,198 @@
|
|||||||
|
package com.baidu.paddle.fastdeploy.app.examples.classification;
|
||||||
|
|
||||||
|
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 ClassificationSettingsActivity extends AppCompatPreferenceActivity implements
|
||||||
|
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
private static final String TAG = ClassificationSettingsActivity.class.getSimpleName();
|
||||||
|
|
||||||
|
static public int selectedModelIdx = -1;
|
||||||
|
static public String modelDir = "";
|
||||||
|
static public String labelPath = "";
|
||||||
|
static public int cpuThreadNum = 2;
|
||||||
|
static public String cpuPowerMode = "";
|
||||||
|
static public float scoreThreshold = 0.1f;
|
||||||
|
static public String enableLiteFp16 = "true";
|
||||||
|
|
||||||
|
ListPreference lpChoosePreInstalledModel = null;
|
||||||
|
EditTextPreference etModelDir = null;
|
||||||
|
EditTextPreference etLabelPath = null;
|
||||||
|
ListPreference lpCPUThreadNum = null;
|
||||||
|
ListPreference lpCPUPowerMode = null;
|
||||||
|
EditTextPreference etScoreThreshold = null;
|
||||||
|
ListPreference lpEnableLiteFp16 = null;
|
||||||
|
|
||||||
|
List<String> preInstalledModelDirs = null;
|
||||||
|
List<String> preInstalledLabelPaths = 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.classification_settings);
|
||||||
|
ActionBar supportActionBar = getSupportActionBar();
|
||||||
|
if (supportActionBar != null) {
|
||||||
|
supportActionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize pre-installed models
|
||||||
|
preInstalledModelDirs = new ArrayList<String>();
|
||||||
|
preInstalledLabelPaths = new ArrayList<String>();
|
||||||
|
preInstalledCPUThreadNums = new ArrayList<String>();
|
||||||
|
preInstalledCPUPowerModes = new ArrayList<String>();
|
||||||
|
preInstalledScoreThresholds = new ArrayList<String>();
|
||||||
|
preInstalledEnableLiteFp16s = new ArrayList<String>();
|
||||||
|
preInstalledModelDirs.add(getString(R.string.CLASSIFICATION_MODEL_DIR_DEFAULT));
|
||||||
|
preInstalledLabelPaths.add(getString(R.string.CLASSIFICATION_LABEL_PATH_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_CLASSIFICATION));
|
||||||
|
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() + ")");
|
||||||
|
etLabelPath = (EditTextPreference) findPreference(getString(R.string.LABEL_PATH_KEY));
|
||||||
|
etLabelPath.setTitle("Label path (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.CLASSIFICATION_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.LABEL_PATH_KEY), preInstalledLabelPaths.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.CLASSIFICATION_MODEL_DIR_DEFAULT));
|
||||||
|
String label_path = sharedPreferences.getString(getString(R.string.LABEL_PATH_KEY),
|
||||||
|
getString(R.string.CLASSIFICATION_LABEL_PATH_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_CLASSIFICATION));
|
||||||
|
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);
|
||||||
|
etLabelPath.setSummary(label_path);
|
||||||
|
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.CLASSIFICATION_MODEL_DIR_DEFAULT));
|
||||||
|
settingsChanged |= !modelDir.equalsIgnoreCase(model_dir);
|
||||||
|
modelDir = model_dir;
|
||||||
|
|
||||||
|
String label_path = sharedPreferences.getString(ctx.getString(R.string.LABEL_PATH_KEY),
|
||||||
|
ctx.getString(R.string.CLASSIFICATION_LABEL_PATH_DEFAULT));
|
||||||
|
settingsChanged |= !labelPath.equalsIgnoreCase(label_path);
|
||||||
|
labelPath = label_path;
|
||||||
|
|
||||||
|
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_CLASSIFICATION));
|
||||||
|
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 = "";
|
||||||
|
labelPath = "";
|
||||||
|
cpuThreadNum = 2;
|
||||||
|
cpuPowerMode = "";
|
||||||
|
scoreThreshold = 0.1f;
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,8 @@
|
|||||||
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,7 +37,7 @@ 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.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;
|
||||||
import com.baidu.paddle.fastdeploy.app.ui.view.adapter.DetectResultAdapter;
|
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.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;
|
||||||
@@ -56,8 +59,8 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
boolean isRealtimeStatusRunning = false;
|
boolean isRealtimeStatusRunning = false;
|
||||||
ImageView backInPreview;
|
ImageView backInPreview;
|
||||||
private ImageView albumSelectButton;
|
private ImageView albumSelectButton;
|
||||||
private View mCameraPageView;
|
private View cameraPageView;
|
||||||
private ViewGroup mResultPageView;
|
private ViewGroup resultPageView;
|
||||||
private ImageView resultImage;
|
private ImageView resultImage;
|
||||||
private ImageView backInResult;
|
private ImageView backInResult;
|
||||||
private SeekBar confidenceSeekbar;
|
private SeekBar confidenceSeekbar;
|
||||||
@@ -68,6 +71,7 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
private Bitmap originShutterBitmap;
|
private Bitmap originShutterBitmap;
|
||||||
private Bitmap picBitmap;
|
private Bitmap picBitmap;
|
||||||
private Bitmap originPicBitmap;
|
private Bitmap originPicBitmap;
|
||||||
|
|
||||||
public static final int TYPE_UNKNOWN = -1;
|
public static final int TYPE_UNKNOWN = -1;
|
||||||
public static final int BTN_SHUTTER = 0;
|
public static final int BTN_SHUTTER = 0;
|
||||||
public static final int ALBUM_SELECT = 1;
|
public static final int ALBUM_SELECT = 1;
|
||||||
@@ -115,8 +119,8 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
case R.id.btn_shutter:
|
case R.id.btn_shutter:
|
||||||
TYPE = BTN_SHUTTER;
|
TYPE = BTN_SHUTTER;
|
||||||
svPreview.onPause();
|
svPreview.onPause();
|
||||||
mCameraPageView.setVisibility(View.GONE);
|
cameraPageView.setVisibility(View.GONE);
|
||||||
mResultPageView.setVisibility(View.VISIBLE);
|
resultPageView.setVisibility(View.VISIBLE);
|
||||||
seekbarText.setText(resultNum + "");
|
seekbarText.setText(resultNum + "");
|
||||||
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
||||||
resultImage.setImageBitmap(shutterBitmap);
|
resultImage.setImageBitmap(shutterBitmap);
|
||||||
@@ -132,9 +136,9 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
break;
|
break;
|
||||||
case R.id.albumSelect:
|
case R.id.albumSelect:
|
||||||
TYPE = ALBUM_SELECT;
|
TYPE = ALBUM_SELECT;
|
||||||
// 判断是否已经赋予权限
|
// Judge whether authority has been granted.
|
||||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||||
// 如果应用之前请求过此权限但用户拒绝了请求,此方法将返回 true。
|
// 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);
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION_CODE_STORAGE);
|
||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(Intent.ACTION_PICK);
|
Intent intent = new Intent(Intent.ACTION_PICK);
|
||||||
@@ -143,8 +147,8 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case R.id.back_in_result:
|
case R.id.back_in_result:
|
||||||
mResultPageView.setVisibility(View.GONE);
|
resultPageView.setVisibility(View.GONE);
|
||||||
mCameraPageView.setVisibility(View.VISIBLE);
|
cameraPageView.setVisibility(View.VISIBLE);
|
||||||
svPreview.onResume();
|
svPreview.onResume();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -156,12 +160,12 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
if (requestCode == INTENT_CODE_PICK_IMAGE) {
|
if (requestCode == INTENT_CODE_PICK_IMAGE) {
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
mCameraPageView.setVisibility(View.GONE);
|
cameraPageView.setVisibility(View.GONE);
|
||||||
mResultPageView.setVisibility(View.VISIBLE);
|
resultPageView.setVisibility(View.VISIBLE);
|
||||||
seekbarText.setText(resultNum + "");
|
seekbarText.setText(resultNum + "");
|
||||||
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
||||||
Uri uri = data.getData();
|
Uri uri = data.getData();
|
||||||
String path = getRealPathFromURI(uri);
|
String path = getRealPathFromURI(this, uri);
|
||||||
picBitmap = decodeBitmap(path, 720, 1280);
|
picBitmap = decodeBitmap(path, 720, 1280);
|
||||||
originPicBitmap = picBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
originPicBitmap = picBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||||
resultImage.setImageBitmap(picBitmap);
|
resultImage.setImageBitmap(picBitmap);
|
||||||
@@ -169,25 +173,6 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRealPathFromURI(Uri contentURI) {
|
|
||||||
String result;
|
|
||||||
Cursor cursor = null;
|
|
||||||
try {
|
|
||||||
cursor = getContentResolver().query(contentURI, null, null, null, null);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (cursor == null) {
|
|
||||||
result = contentURI.getPath();
|
|
||||||
} else {
|
|
||||||
cursor.moveToFirst();
|
|
||||||
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
|
|
||||||
result = cursor.getString(idx);
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void toggleRealtimeStyle() {
|
private void toggleRealtimeStyle() {
|
||||||
if (isRealtimeStatusRunning) {
|
if (isRealtimeStatusRunning) {
|
||||||
isRealtimeStatusRunning = false;
|
isRealtimeStatusRunning = false;
|
||||||
@@ -217,7 +202,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);
|
||||||
} else {
|
} else {
|
||||||
// Only reference in detecting loops.
|
// Only reference in predict loops.
|
||||||
shutterBitmap = ARGB8888ImageBitmap;
|
shutterBitmap = ARGB8888ImageBitmap;
|
||||||
originShutterBitmap = ARGB8888ImageBitmap;
|
originShutterBitmap = ARGB8888ImageBitmap;
|
||||||
}
|
}
|
||||||
@@ -226,7 +211,6 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
DetectionResult result = predictor.predict(
|
DetectionResult result = predictor.predict(
|
||||||
ARGB8888ImageBitmap, true, DetectionSettingsActivity.scoreThreshold);
|
ARGB8888ImageBitmap, true, DetectionSettingsActivity.scoreThreshold);
|
||||||
modified = result.initialized();
|
modified = result.initialized();
|
||||||
|
|
||||||
if (!savedImagePath.isEmpty()) {
|
if (!savedImagePath.isEmpty()) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
DetectionMainActivity.this.savedImagePath = "result.jpg";
|
DetectionMainActivity.this.savedImagePath = "result.jpg";
|
||||||
@@ -247,38 +231,6 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param path 路径
|
|
||||||
* @param displayWidth 需要显示的宽度
|
|
||||||
* @param displayHeight 需要显示的高度
|
|
||||||
* @return Bitmap
|
|
||||||
*/
|
|
||||||
public static Bitmap decodeBitmap(String path, int displayWidth, int displayHeight) {
|
|
||||||
BitmapFactory.Options op = new BitmapFactory.Options();
|
|
||||||
op.inJustDecodeBounds = true;
|
|
||||||
// op.inJustDecodeBounds = true;表示我们只读取Bitmap的宽高等信息,不读取像素。
|
|
||||||
Bitmap bmp = BitmapFactory.decodeFile(path, op); // 获取尺寸信息
|
|
||||||
// op.outWidth表示的是图像真实的宽度
|
|
||||||
// op.inSamplySize 表示的是缩小的比例
|
|
||||||
// op.inSamplySize = 4,表示缩小1/4的宽和高,1/16的像素,android认为设置为2是最快的。
|
|
||||||
// 获取比例大小
|
|
||||||
int wRatio = (int) Math.ceil(op.outWidth / (float) displayWidth);
|
|
||||||
int hRatio = (int) Math.ceil(op.outHeight / (float) displayHeight);
|
|
||||||
// 如果超出指定大小,则缩小相应的比例
|
|
||||||
if (wRatio > 1 && hRatio > 1) {
|
|
||||||
if (wRatio > hRatio) {
|
|
||||||
// 如果太宽,我们就缩小宽度到需要的大小,注意,高度就会变得更加的小。
|
|
||||||
op.inSampleSize = wRatio;
|
|
||||||
} else {
|
|
||||||
op.inSampleSize = hRatio;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
op.inJustDecodeBounds = false;
|
|
||||||
bmp = BitmapFactory.decodeFile(path, op);
|
|
||||||
// 从原Bitmap创建一个给定宽高的Bitmap
|
|
||||||
return Bitmap.createScaledBitmap(bmp, displayWidth, displayHeight, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@@ -306,6 +258,7 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initView() {
|
public void initView() {
|
||||||
|
TYPE = BTN_SHUTTER;
|
||||||
svPreview = (CameraSurfaceView) findViewById(R.id.sv_preview);
|
svPreview = (CameraSurfaceView) findViewById(R.id.sv_preview);
|
||||||
svPreview.setOnTextureChangedListener(this);
|
svPreview.setOnTextureChangedListener(this);
|
||||||
tvStatus = (TextView) findViewById(R.id.tv_status);
|
tvStatus = (TextView) findViewById(R.id.tv_status);
|
||||||
@@ -321,8 +274,8 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
backInPreview.setOnClickListener(this);
|
backInPreview.setOnClickListener(this);
|
||||||
albumSelectButton = findViewById(R.id.albumSelect);
|
albumSelectButton = findViewById(R.id.albumSelect);
|
||||||
albumSelectButton.setOnClickListener(this);
|
albumSelectButton.setOnClickListener(this);
|
||||||
mCameraPageView = findViewById(R.id.camera_page);
|
cameraPageView = findViewById(R.id.camera_page);
|
||||||
mResultPageView = findViewById(R.id.result_page);
|
resultPageView = findViewById(R.id.result_page);
|
||||||
resultImage = findViewById(R.id.result_image);
|
resultImage = findViewById(R.id.result_image);
|
||||||
backInResult = findViewById(R.id.back_in_result);
|
backInResult = findViewById(R.id.back_in_result);
|
||||||
backInResult.setOnClickListener(this);
|
backInResult.setOnClickListener(this);
|
||||||
@@ -334,7 +287,7 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
results.add(new BaseResultModel(1, "cup", 0.4f));
|
results.add(new BaseResultModel(1, "cup", 0.4f));
|
||||||
results.add(new BaseResultModel(2, "pen", 0.6f));
|
results.add(new BaseResultModel(2, "pen", 0.6f));
|
||||||
results.add(new BaseResultModel(3, "tang", 1.0f));
|
results.add(new BaseResultModel(3, "tang", 1.0f));
|
||||||
final DetectResultAdapter adapter = new DetectResultAdapter(this, R.layout.detection_result_page_item, results);
|
final BaseResultAdapter adapter = new BaseResultAdapter(this, R.layout.detection_result_page_item, results);
|
||||||
detectResultView.setAdapter(adapter);
|
detectResultView.setAdapter(adapter);
|
||||||
detectResultView.invalidate();
|
detectResultView.invalidate();
|
||||||
|
|
||||||
|
@@ -59,8 +59,8 @@ public class DetectionSettingsActivity extends AppCompatPreferenceActivity imple
|
|||||||
preInstalledCPUPowerModes = new ArrayList<String>();
|
preInstalledCPUPowerModes = new ArrayList<String>();
|
||||||
preInstalledScoreThresholds = new ArrayList<String>();
|
preInstalledScoreThresholds = new ArrayList<String>();
|
||||||
preInstalledEnableLiteFp16s = new ArrayList<String>();
|
preInstalledEnableLiteFp16s = new ArrayList<String>();
|
||||||
preInstalledModelDirs.add(getString(R.string.MODEL_DIR_DEFAULT));
|
preInstalledModelDirs.add(getString(R.string.DETECTION_MODEL_DIR_DEFAULT));
|
||||||
preInstalledLabelPaths.add(getString(R.string.LABEL_PATH_DEFAULT));
|
preInstalledLabelPaths.add(getString(R.string.DETECTION_LABEL_PATH_DEFAULT));
|
||||||
preInstalledCPUThreadNums.add(getString(R.string.CPU_THREAD_NUM_DEFAULT));
|
preInstalledCPUThreadNums.add(getString(R.string.CPU_THREAD_NUM_DEFAULT));
|
||||||
preInstalledCPUPowerModes.add(getString(R.string.CPU_POWER_MODE_DEFAULT));
|
preInstalledCPUPowerModes.add(getString(R.string.CPU_POWER_MODE_DEFAULT));
|
||||||
preInstalledScoreThresholds.add(getString(R.string.SCORE_THRESHOLD_DEFAULT));
|
preInstalledScoreThresholds.add(getString(R.string.SCORE_THRESHOLD_DEFAULT));
|
||||||
@@ -90,7 +90,7 @@ public class DetectionSettingsActivity extends AppCompatPreferenceActivity imple
|
|||||||
SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
|
SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
|
||||||
|
|
||||||
String selected_model_dir = sharedPreferences.getString(getString(R.string.CHOOSE_PRE_INSTALLED_MODEL_KEY),
|
String selected_model_dir = sharedPreferences.getString(getString(R.string.CHOOSE_PRE_INSTALLED_MODEL_KEY),
|
||||||
getString(R.string.MODEL_DIR_DEFAULT));
|
getString(R.string.DETECTION_MODEL_DIR_DEFAULT));
|
||||||
int selected_model_idx = lpChoosePreInstalledModel.findIndexOfValue(selected_model_dir);
|
int selected_model_idx = lpChoosePreInstalledModel.findIndexOfValue(selected_model_dir);
|
||||||
if (selected_model_idx >= 0 && selected_model_idx < preInstalledModelDirs.size() && selected_model_idx != selectedModelIdx) {
|
if (selected_model_idx >= 0 && selected_model_idx < preInstalledModelDirs.size() && selected_model_idx != selectedModelIdx) {
|
||||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||||
@@ -106,9 +106,9 @@ public class DetectionSettingsActivity extends AppCompatPreferenceActivity imple
|
|||||||
}
|
}
|
||||||
|
|
||||||
String model_dir = sharedPreferences.getString(getString(R.string.MODEL_DIR_KEY),
|
String model_dir = sharedPreferences.getString(getString(R.string.MODEL_DIR_KEY),
|
||||||
getString(R.string.MODEL_DIR_DEFAULT));
|
getString(R.string.DETECTION_MODEL_DIR_DEFAULT));
|
||||||
String label_path = sharedPreferences.getString(getString(R.string.LABEL_PATH_KEY),
|
String label_path = sharedPreferences.getString(getString(R.string.LABEL_PATH_KEY),
|
||||||
getString(R.string.LABEL_PATH_DEFAULT));
|
getString(R.string.DETECTION_LABEL_PATH_DEFAULT));
|
||||||
String cpu_thread_num = sharedPreferences.getString(getString(R.string.CPU_THREAD_NUM_KEY),
|
String cpu_thread_num = sharedPreferences.getString(getString(R.string.CPU_THREAD_NUM_KEY),
|
||||||
getString(R.string.CPU_THREAD_NUM_DEFAULT));
|
getString(R.string.CPU_THREAD_NUM_DEFAULT));
|
||||||
String cpu_power_mode = sharedPreferences.getString(getString(R.string.CPU_POWER_MODE_KEY),
|
String cpu_power_mode = sharedPreferences.getString(getString(R.string.CPU_POWER_MODE_KEY),
|
||||||
@@ -136,12 +136,12 @@ public class DetectionSettingsActivity extends AppCompatPreferenceActivity imple
|
|||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx);
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||||
|
|
||||||
String model_dir = sharedPreferences.getString(ctx.getString(R.string.MODEL_DIR_KEY),
|
String model_dir = sharedPreferences.getString(ctx.getString(R.string.MODEL_DIR_KEY),
|
||||||
ctx.getString(R.string.MODEL_DIR_DEFAULT));
|
ctx.getString(R.string.DETECTION_MODEL_DIR_DEFAULT));
|
||||||
settingsChanged |= !modelDir.equalsIgnoreCase(model_dir);
|
settingsChanged |= !modelDir.equalsIgnoreCase(model_dir);
|
||||||
modelDir = model_dir;
|
modelDir = model_dir;
|
||||||
|
|
||||||
String label_path = sharedPreferences.getString(ctx.getString(R.string.LABEL_PATH_KEY),
|
String label_path = sharedPreferences.getString(ctx.getString(R.string.LABEL_PATH_KEY),
|
||||||
ctx.getString(R.string.LABEL_PATH_DEFAULT));
|
ctx.getString(R.string.DETECTION_LABEL_PATH_DEFAULT));
|
||||||
settingsChanged |= !labelPath.equalsIgnoreCase(label_path);
|
settingsChanged |= !labelPath.equalsIgnoreCase(label_path);
|
||||||
labelPath = label_path;
|
labelPath = label_path;
|
||||||
|
|
||||||
|
@@ -2,9 +2,14 @@ package com.baidu.paddle.fastdeploy.app.ui;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
|
import android.net.Uri;
|
||||||
import android.opengl.GLES20;
|
import android.opengl.GLES20;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
@@ -241,4 +246,44 @@ public class Utils {
|
|||||||
String hardware = android.os.Build.HARDWARE;
|
String hardware = android.os.Build.HARDWARE;
|
||||||
return hardware.equalsIgnoreCase("kirin810") || hardware.equalsIgnoreCase("kirin990");
|
return hardware.equalsIgnoreCase("kirin810") || hardware.equalsIgnoreCase("kirin990");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Bitmap decodeBitmap(String path, int displayWidth, int displayHeight) {
|
||||||
|
BitmapFactory.Options op = new BitmapFactory.Options();
|
||||||
|
op.inJustDecodeBounds = true;// Only the width and height information of Bitmap is read, not the pixels.
|
||||||
|
Bitmap bmp = BitmapFactory.decodeFile(path, op); // Get size information.
|
||||||
|
int wRatio = (int) Math.ceil(op.outWidth / (float) displayWidth);// Get Scale Size.
|
||||||
|
int hRatio = (int) Math.ceil(op.outHeight / (float) displayHeight);
|
||||||
|
// If the specified size is exceeded, reduce the corresponding scale.
|
||||||
|
if (wRatio > 1 && hRatio > 1) {
|
||||||
|
if (wRatio > hRatio) {
|
||||||
|
// If it is too wide, we will reduce the width to the required size. Note that the height will become smaller.
|
||||||
|
op.inSampleSize = wRatio;
|
||||||
|
} else {
|
||||||
|
op.inSampleSize = hRatio;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
op.inJustDecodeBounds = false;
|
||||||
|
bmp = BitmapFactory.decodeFile(path, op);
|
||||||
|
// Create a Bitmap with a given width and height from the original Bitmap.
|
||||||
|
return Bitmap.createScaledBitmap(bmp, displayWidth, displayHeight, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getRealPathFromURI(Context context, Uri contentURI) {
|
||||||
|
String result;
|
||||||
|
Cursor cursor = null;
|
||||||
|
try {
|
||||||
|
cursor = context.getContentResolver().query(contentURI, null, null, null, null);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (cursor == null) {
|
||||||
|
result = contentURI.getPath();
|
||||||
|
} else {
|
||||||
|
cursor.moveToFirst();
|
||||||
|
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
|
||||||
|
result = cursor.getString(idx);
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,14 +15,14 @@ import com.baidu.paddle.fastdeploy.app.ui.view.model.BaseResultModel;
|
|||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DetectResultAdapter extends ArrayAdapter<BaseResultModel> {
|
public class BaseResultAdapter extends ArrayAdapter<BaseResultModel> {
|
||||||
private int resourceId;
|
private int resourceId;
|
||||||
|
|
||||||
public DetectResultAdapter(@NonNull Context context, int resource) {
|
public BaseResultAdapter(@NonNull Context context, int resource) {
|
||||||
super(context, resource);
|
super(context, resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DetectResultAdapter(@NonNull Context context, int resource, @NonNull List<BaseResultModel> objects) {
|
public BaseResultAdapter(@NonNull Context context, int resource, @NonNull List<BaseResultModel> objects) {
|
||||||
super(context, resource, objects);
|
super(context, resource, objects);
|
||||||
resourceId = resource;
|
resourceId = resource;
|
||||||
}
|
}
|
@@ -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/classification_camera_page"
|
||||||
|
android:id="@+id/camera_page"></include>
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/classification_result_page"
|
||||||
|
android:id="@+id/result_page"
|
||||||
|
android:visibility="gone"></include>
|
||||||
|
</FrameLayout>
|
@@ -0,0 +1,161 @@
|
|||||||
|
<?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=".detection.DetectionMainActivity">
|
||||||
|
|
||||||
|
<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"
|
||||||
|
android:textSize="15sp"/>
|
||||||
|
</LinearLayout>
|
||||||
|
</com.baidu.paddle.fastdeploy.app.ui.layout.ActionBarLayout>
|
||||||
|
|
||||||
|
<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/albumSelect"
|
||||||
|
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>
|
@@ -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>
|
@@ -42,18 +42,17 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/action_bar_take_photo"
|
android:text="@string/action_bar_take_photo"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/action_realtime_btn"
|
android:id="@+id/action_realtime_btn"
|
||||||
style="@style/action_btn"
|
style="@style/action_btn"
|
||||||
android:layout_width="300px"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/action_bar_realtime"
|
android:text="@string/action_bar_realtime"
|
||||||
android:textAlignment="center" />
|
android:textAlignment="center" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- 实时-->
|
|
||||||
<com.baidu.paddle.fastdeploy.app.ui.view.CameraSurfaceView
|
<com.baidu.paddle.fastdeploy.app.ui.view.CameraSurfaceView
|
||||||
android:id="@+id/sv_preview"
|
android:id="@+id/sv_preview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
<!-- Other App name -->
|
<!-- Other App name -->
|
||||||
<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>
|
||||||
<!-- 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>
|
||||||
@@ -16,17 +17,21 @@
|
|||||||
<string name="CPU_THREAD_NUM_DEFAULT">2</string>
|
<string name="CPU_THREAD_NUM_DEFAULT">2</string>
|
||||||
<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="ENABLE_LITE_FP16_MODE_DEFAULT">true</string>
|
<string name="ENABLE_LITE_FP16_MODE_DEFAULT">true</string>
|
||||||
<!--Other values-->
|
<!--Other values-->
|
||||||
<!-- Default model & Label paths & other values ... -->
|
<!-- Detection model & Label paths & other values ... -->
|
||||||
<string name="MODEL_DIR_DEFAULT">models/picodet_s_320_coco_lcnet</string>
|
<string name="DETECTION_MODEL_DIR_DEFAULT">models/picodet_s_320_coco_lcnet</string>
|
||||||
<string name="LABEL_PATH_DEFAULT">labels/coco_label_list.txt</string>
|
<string name="DETECTION_LABEL_PATH_DEFAULT">labels/coco_label_list.txt</string>
|
||||||
<!-- PP-OCRv2 & PP-OCRv3 values ... -->
|
<!-- PP-OCRv2 & PP-OCRv3 values ... -->
|
||||||
<string name="OCR_MODEL_DIR_DEFAULT">models</string>
|
<string name="OCR_MODEL_DIR_DEFAULT">models</string>
|
||||||
<string name="OCR_REC_LABEL_DEFAULT">labels/ppocr_keys_v1.txt</string>
|
<string name="OCR_REC_LABEL_DEFAULT">labels/ppocr_keys_v1.txt</string>
|
||||||
|
<!-- classification values ... -->
|
||||||
|
<string name="CLASSIFICATION_MODEL_DIR_DEFAULT">models/MobileNetV1_x0_25_infer</string>
|
||||||
|
<string name="CLASSIFICATION_LABEL_PATH_DEFAULT">labels/imagenet1k_label_list.txt</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">EasyEdge 实时识别</string>
|
<string name="action_bar_realtime">实时识别</string>
|
||||||
<string name="action_bar_back"><</string>
|
<string name="action_bar_back"><</string>
|
||||||
<string name="action_bar_model_name">模型名称</string>
|
<string name="action_bar_model_name">模型名称</string>
|
||||||
<string name="result_label">识别结果</string>
|
<string name="result_label">识别结果</string>
|
||||||
|
@@ -1,4 +1,45 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="@string/CLASSIFICATION_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/CLASSIFICATION_MODEL_DIR_DEFAULT"
|
||||||
|
android:key="@string/MODEL_DIR_KEY"
|
||||||
|
android:title="Model Dir" />
|
||||||
|
<EditTextPreference
|
||||||
|
android:defaultValue="@string/CLASSIFICATION_LABEL_PATH_DEFAULT"
|
||||||
|
android:key="@string/LABEL_PATH_KEY"
|
||||||
|
android:title="Label Path" />
|
||||||
|
<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_CLASSIFICATION"
|
||||||
|
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>
|
</PreferenceScreen>
|
@@ -1,45 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<ListPreference
|
|
||||||
android:defaultValue="@string/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/MODEL_DIR_DEFAULT"
|
|
||||||
android:key="@string/MODEL_DIR_KEY"
|
|
||||||
android:title="Model Dir" />
|
|
||||||
<EditTextPreference
|
|
||||||
android:defaultValue="@string/LABEL_PATH_DEFAULT"
|
|
||||||
android:key="@string/LABEL_PATH_KEY"
|
|
||||||
android:title="Label Path" />
|
|
||||||
<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>
|
|
@@ -1,17 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:defaultValue="@string/MODEL_DIR_DEFAULT"
|
android:defaultValue="@string/DETECTION_MODEL_DIR_DEFAULT"
|
||||||
android:key="@string/CHOOSE_PRE_INSTALLED_MODEL_KEY"
|
android:key="@string/CHOOSE_PRE_INSTALLED_MODEL_KEY"
|
||||||
android:negativeButtonText="@null"
|
android:negativeButtonText="@null"
|
||||||
android:positiveButtonText="@null"
|
android:positiveButtonText="@null"
|
||||||
android:title="Choose Pre-Installed Models" />
|
android:title="Choose Pre-Installed Models" />
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="@string/MODEL_DIR_DEFAULT"
|
android:defaultValue="@string/DETECTION_MODEL_DIR_DEFAULT"
|
||||||
android:key="@string/MODEL_DIR_KEY"
|
android:key="@string/MODEL_DIR_KEY"
|
||||||
android:title="Model Dir" />
|
android:title="Model Dir" />
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="@string/LABEL_PATH_DEFAULT"
|
android:defaultValue="@string/DETECTION_LABEL_PATH_DEFAULT"
|
||||||
android:key="@string/LABEL_PATH_KEY"
|
android:key="@string/LABEL_PATH_KEY"
|
||||||
android:title="Label Path" />
|
android:title="Label Path" />
|
||||||
<ListPreference
|
<ListPreference
|
||||||
|
Reference in New Issue
Block a user