mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 08:37:06 +08:00
[Android] Configure face recognition and segmentation details page (#619)
* 1.Classification Code submission; 2.Specification code format. * Specification code format. * Update strings.xml * 1.Display ocr, detection and classification results. 2.Specification code format. * Configure face recognition and semantic segmentation details page. Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,7 @@ 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.decodeBitmap;
|
||||||
import static com.baidu.paddle.fastdeploy.app.ui.Utils.getRealPathFromURI;
|
import static com.baidu.paddle.fastdeploy.app.ui.Utils.getRealPathFromURI;
|
||||||
|
import static com.baidu.paddle.fastdeploy.app.ui.Utils.readTxt;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
@@ -36,9 +37,9 @@ 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.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.ClassifyResult;
|
import com.baidu.paddle.fastdeploy.vision.ClassifyResult;
|
||||||
|
import com.baidu.paddle.fastdeploy.vision.Visualize;
|
||||||
import com.baidu.paddle.fastdeploy.vision.classification.PaddleClasModel;
|
import com.baidu.paddle.fastdeploy.vision.classification.PaddleClasModel;
|
||||||
|
|
||||||
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;
|
||||||
@@ -62,27 +63,33 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
|
|||||||
private SeekBar confidenceSeekbar;
|
private SeekBar confidenceSeekbar;
|
||||||
private TextView seekbarText;
|
private TextView seekbarText;
|
||||||
private float resultNum = 1.0f;
|
private float resultNum = 1.0f;
|
||||||
private ResultListView detectResultView;
|
private ResultListView resultView;
|
||||||
private Bitmap shutterBitmap;
|
private Bitmap shutterBitmap;
|
||||||
private Bitmap originShutterBitmap;
|
|
||||||
private Bitmap picBitmap;
|
private Bitmap picBitmap;
|
||||||
private Bitmap originPicBitmap;
|
private boolean isShutterBitmapCopied = false;
|
||||||
|
|
||||||
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;
|
||||||
private static int TYPE = TYPE_UNKNOWN;
|
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 REQUEST_PERMISSION_CODE_STORAGE = 101;
|
||||||
private static final int INTENT_CODE_PICK_IMAGE = 100;
|
private static final int INTENT_CODE_PICK_IMAGE = 100;
|
||||||
|
private static final int TIME_SLEEP_INTERVAL = 50; // ms
|
||||||
|
|
||||||
String savedImagePath = "result.jpg";
|
|
||||||
long timeElapsed = 0;
|
long timeElapsed = 0;
|
||||||
long frameCounter = 0;
|
long frameCounter = 0;
|
||||||
|
|
||||||
// Call 'init' and 'release' manually later
|
// Call 'init' and 'release' manually later
|
||||||
PaddleClasModel predictor = new PaddleClasModel();
|
PaddleClasModel predictor = new PaddleClasModel();
|
||||||
|
|
||||||
|
private float[] scores;
|
||||||
|
private int[] labelId;
|
||||||
|
private boolean initialized;
|
||||||
|
private List<String> labelText;
|
||||||
|
private List<BaseResultModel> results = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -114,12 +121,8 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
|
|||||||
break;
|
break;
|
||||||
case R.id.btn_shutter:
|
case R.id.btn_shutter:
|
||||||
TYPE = BTN_SHUTTER;
|
TYPE = BTN_SHUTTER;
|
||||||
svPreview.onPause();
|
shutterAndPauseCamera();
|
||||||
cameraPageView.setVisibility(View.GONE);
|
resultView.setAdapter(null);
|
||||||
resultPageView.setVisibility(View.VISIBLE);
|
|
||||||
seekbarText.setText(resultNum + "");
|
|
||||||
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
|
||||||
resultImage.setImageBitmap(shutterBitmap);
|
|
||||||
break;
|
break;
|
||||||
case R.id.btn_settings:
|
case R.id.btn_settings:
|
||||||
startActivity(new Intent(ClassificationMainActivity.this, ClassificationSettingsActivity.class));
|
startActivity(new Intent(ClassificationMainActivity.this, ClassificationSettingsActivity.class));
|
||||||
@@ -130,7 +133,7 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
|
|||||||
case R.id.back_in_preview:
|
case R.id.back_in_preview:
|
||||||
finish();
|
finish();
|
||||||
break;
|
break;
|
||||||
case R.id.albumSelect:
|
case R.id.iv_select:
|
||||||
TYPE = ALBUM_SELECT;
|
TYPE = ALBUM_SELECT;
|
||||||
// Judge whether authority has been granted.
|
// 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) {
|
||||||
@@ -141,16 +144,84 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
|
|||||||
intent.setType("image/*");
|
intent.setType("image/*");
|
||||||
startActivityForResult(intent, INTENT_CODE_PICK_IMAGE);
|
startActivityForResult(intent, INTENT_CODE_PICK_IMAGE);
|
||||||
}
|
}
|
||||||
|
resultView.setAdapter(null);
|
||||||
break;
|
break;
|
||||||
case R.id.back_in_result:
|
case R.id.back_in_result:
|
||||||
resultPageView.setVisibility(View.GONE);
|
back();
|
||||||
cameraPageView.setVisibility(View.VISIBLE);
|
|
||||||
svPreview.onResume();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
super.onBackPressed();
|
||||||
|
back();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void back() {
|
||||||
|
resultPageView.setVisibility(View.GONE);
|
||||||
|
cameraPageView.setVisibility(View.VISIBLE);
|
||||||
|
TYPE = REALTIME_DETECT;
|
||||||
|
isShutterBitmapCopied = false;
|
||||||
|
svPreview.onResume();
|
||||||
|
results.clear();
|
||||||
|
if (scores != null) {
|
||||||
|
scores = null;
|
||||||
|
}
|
||||||
|
if (labelId != null) {
|
||||||
|
labelId = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 * 10); // 500ms
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
public void run() {
|
||||||
|
// These code will run in main thread.
|
||||||
|
svPreview.onPause();
|
||||||
|
cameraPageView.setVisibility(View.GONE);
|
||||||
|
resultPageView.setVisibility(View.VISIBLE);
|
||||||
|
seekbarText.setText(resultNum + "");
|
||||||
|
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
||||||
|
if (shutterBitmap != null && !shutterBitmap.isRecycled()) {
|
||||||
|
resultImage.setImageBitmap(shutterBitmap);
|
||||||
|
} else {
|
||||||
|
new AlertDialog.Builder(ClassificationMainActivity.this)
|
||||||
|
.setTitle("Empty Result!")
|
||||||
|
.setMessage("Current picture is empty, please shutting it again!")
|
||||||
|
.setCancelable(true)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyBitmapFromCamera(Bitmap ARGB8888ImageBitmap) {
|
||||||
|
if (isShutterBitmapCopied || ARGB8888ImageBitmap == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!ARGB8888ImageBitmap.isRecycled()) {
|
||||||
|
synchronized (this) {
|
||||||
|
shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||||
|
}
|
||||||
|
SystemClock.sleep(TIME_SLEEP_INTERVAL);
|
||||||
|
isShutterBitmapCopied = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
@@ -163,7 +234,6 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
|
|||||||
Uri uri = data.getData();
|
Uri uri = data.getData();
|
||||||
String path = getRealPathFromURI(this, uri);
|
String path = getRealPathFromURI(this, uri);
|
||||||
picBitmap = decodeBitmap(path, 720, 1280);
|
picBitmap = decodeBitmap(path, 720, 1280);
|
||||||
originPicBitmap = picBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
||||||
resultImage.setImageBitmap(picBitmap);
|
resultImage.setImageBitmap(picBitmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,34 +260,17 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTextureChanged(Bitmap ARGB8888ImageBitmap) {
|
public boolean onTextureChanged(Bitmap ARGB8888ImageBitmap) {
|
||||||
String savedImagePath = "";
|
|
||||||
synchronized (this) {
|
|
||||||
savedImagePath = Utils.getDCIMDirectory() + File.separator + "result.jpg";
|
|
||||||
}
|
|
||||||
if (TYPE == BTN_SHUTTER) {
|
if (TYPE == BTN_SHUTTER) {
|
||||||
shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
copyBitmapFromCamera(ARGB8888ImageBitmap);
|
||||||
originShutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
return false;
|
||||||
} else {
|
|
||||||
// Only reference in predict loops.
|
|
||||||
shutterBitmap = ARGB8888ImageBitmap;
|
|
||||||
originShutterBitmap = ARGB8888ImageBitmap;
|
|
||||||
}
|
}
|
||||||
boolean modified = false;
|
boolean modified = false;
|
||||||
|
|
||||||
long tc = System.currentTimeMillis();
|
long tc = System.currentTimeMillis();
|
||||||
ClassifyResult result = predictor.predict(
|
ClassifyResult result = predictor.predict(ARGB8888ImageBitmap);
|
||||||
ARGB8888ImageBitmap, true, ClassificationSettingsActivity.scoreThreshold);
|
|
||||||
|
|
||||||
timeElapsed += (System.currentTimeMillis() - tc);
|
timeElapsed += (System.currentTimeMillis() - tc);
|
||||||
frameCounter++;
|
Visualize.visClassification(ARGB8888ImageBitmap, result, resultNum, 12);
|
||||||
|
|
||||||
modified = result.initialized();
|
modified = result.initialized();
|
||||||
if (!savedImagePath.isEmpty()) {
|
frameCounter++;
|
||||||
synchronized (this) {
|
|
||||||
ClassificationMainActivity.this.savedImagePath = "result.jpg";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (frameCounter >= 30) {
|
if (frameCounter >= 30) {
|
||||||
final int fps = (int) (1000 / (timeElapsed / 30));
|
final int fps = (int) (1000 / (timeElapsed / 30));
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@@ -259,7 +312,7 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initView() {
|
public void initView() {
|
||||||
TYPE = BTN_SHUTTER;
|
TYPE = REALTIME_DETECT;
|
||||||
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);
|
||||||
@@ -273,7 +326,7 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
|
|||||||
realtimeToggleButton.setOnClickListener(this);
|
realtimeToggleButton.setOnClickListener(this);
|
||||||
backInPreview = findViewById(R.id.back_in_preview);
|
backInPreview = findViewById(R.id.back_in_preview);
|
||||||
backInPreview.setOnClickListener(this);
|
backInPreview.setOnClickListener(this);
|
||||||
albumSelectButton = findViewById(R.id.albumSelect);
|
albumSelectButton = findViewById(R.id.iv_select);
|
||||||
albumSelectButton.setOnClickListener(this);
|
albumSelectButton.setOnClickListener(this);
|
||||||
cameraPageView = findViewById(R.id.camera_page);
|
cameraPageView = findViewById(R.id.camera_page);
|
||||||
resultPageView = findViewById(R.id.result_page);
|
resultPageView = findViewById(R.id.result_page);
|
||||||
@@ -282,15 +335,7 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
|
|||||||
backInResult.setOnClickListener(this);
|
backInResult.setOnClickListener(this);
|
||||||
confidenceSeekbar = findViewById(R.id.confidence_seekbar);
|
confidenceSeekbar = findViewById(R.id.confidence_seekbar);
|
||||||
seekbarText = findViewById(R.id.seekbar_text);
|
seekbarText = findViewById(R.id.seekbar_text);
|
||||||
detectResultView = findViewById(R.id.result_list_view);
|
resultView = 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.setMax(100);
|
||||||
confidenceSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
confidenceSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
@@ -301,6 +346,7 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
|
|||||||
resultNum = bd.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
|
resultNum = bd.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
|
||||||
seekbarText.setText(resultNum + "");
|
seekbarText.setText(resultNum + "");
|
||||||
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
||||||
|
results.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -315,22 +361,45 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (TYPE == ALBUM_SELECT) {
|
if (TYPE == ALBUM_SELECT) {
|
||||||
SystemClock.sleep(500);
|
SystemClock.sleep(500);
|
||||||
predictor.predict(picBitmap, savedImagePath, resultNum);
|
detail(picBitmap);
|
||||||
resultImage.setImageBitmap(picBitmap);
|
|
||||||
picBitmap = originPicBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
||||||
resultNum = 1.0f;
|
|
||||||
} else {
|
} else {
|
||||||
SystemClock.sleep(500);
|
SystemClock.sleep(500);
|
||||||
predictor.predict(shutterBitmap, savedImagePath, resultNum);
|
svPreview.onPause();
|
||||||
resultImage.setImageBitmap(shutterBitmap);
|
detail(shutterBitmap);
|
||||||
shutterBitmap = originShutterBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void detail(Bitmap bitmap) {
|
||||||
|
ClassifyResult result = predictor.predict(bitmap, true, ClassificationSettingsActivity.scoreThreshold);
|
||||||
|
if (scores == null) {
|
||||||
|
scores = result.mScores;
|
||||||
|
}
|
||||||
|
if (labelId == null) {
|
||||||
|
labelId = result.mLabelIds;
|
||||||
|
}
|
||||||
|
initialized = result.initialized();
|
||||||
|
if (initialized) {
|
||||||
|
for (int i = 0; i < labelId.length; i++) {
|
||||||
|
for (int j = 0; j < labelText.size(); j++) {
|
||||||
|
if (scores[i] > resultNum) {
|
||||||
|
if (labelId[i] == Integer.parseInt(labelText.get(j).substring(0, labelText.get(j).indexOf(" ")))) {
|
||||||
|
results.add(new BaseResultModel(labelId[i], labelText.get(j), scores[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BaseResultAdapter adapter = new BaseResultAdapter(getBaseContext(), R.layout.ocr_result_page_item, results);
|
||||||
|
resultView.setAdapter(adapter);
|
||||||
|
resultView.invalidate();
|
||||||
|
|
||||||
|
resultImage.setImageBitmap(bitmap);
|
||||||
resultNum = 1.0f;
|
resultNum = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
public void initSettings() {
|
public void initSettings() {
|
||||||
@@ -352,6 +421,7 @@ public class ClassificationMainActivity extends Activity implements View.OnClick
|
|||||||
String paramsFile = realModelDir + "/" + "inference.pdiparams";
|
String paramsFile = realModelDir + "/" + "inference.pdiparams";
|
||||||
String configFile = realModelDir + "/" + "inference_cls.yaml";
|
String configFile = realModelDir + "/" + "inference_cls.yaml";
|
||||||
String labelFile = realLabelPath;
|
String labelFile = realLabelPath;
|
||||||
|
labelText = readTxt(labelFile);
|
||||||
RuntimeOption option = new RuntimeOption();
|
RuntimeOption option = new RuntimeOption();
|
||||||
option.setCpuThreadNum(ClassificationSettingsActivity.cpuThreadNum);
|
option.setCpuThreadNum(ClassificationSettingsActivity.cpuThreadNum);
|
||||||
option.setLitePowerMode(ClassificationSettingsActivity.cpuPowerMode);
|
option.setLitePowerMode(ClassificationSettingsActivity.cpuPowerMode);
|
||||||
|
@@ -8,18 +8,14 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.provider.MediaStore;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
@@ -31,7 +27,6 @@ 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;
|
||||||
@@ -43,8 +38,8 @@ 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.decodeBitmap;
|
||||||
import static com.baidu.paddle.fastdeploy.app.ui.Utils.getRealPathFromURI;
|
import static com.baidu.paddle.fastdeploy.app.ui.Utils.getRealPathFromURI;
|
||||||
|
import static com.baidu.paddle.fastdeploy.app.ui.Utils.readTxt;
|
||||||
|
|
||||||
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;
|
||||||
@@ -68,11 +63,9 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
private SeekBar confidenceSeekbar;
|
private SeekBar confidenceSeekbar;
|
||||||
private TextView seekbarText;
|
private TextView seekbarText;
|
||||||
private float resultNum = 1.0f;
|
private float resultNum = 1.0f;
|
||||||
private ResultListView detectResultView;
|
private ResultListView resultView;
|
||||||
private Bitmap shutterBitmap;
|
private Bitmap shutterBitmap;
|
||||||
private Bitmap originShutterBitmap;
|
|
||||||
private Bitmap picBitmap;
|
private Bitmap picBitmap;
|
||||||
private Bitmap originPicBitmap;
|
|
||||||
private boolean isShutterBitmapCopied = false;
|
private boolean isShutterBitmapCopied = false;
|
||||||
|
|
||||||
public static final int TYPE_UNKNOWN = -1;
|
public static final int TYPE_UNKNOWN = -1;
|
||||||
@@ -85,13 +78,18 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
private static final int INTENT_CODE_PICK_IMAGE = 100;
|
private static final int INTENT_CODE_PICK_IMAGE = 100;
|
||||||
private static final int TIME_SLEEP_INTERVAL = 50; // ms
|
private static final int TIME_SLEEP_INTERVAL = 50; // ms
|
||||||
|
|
||||||
String savedImagePath = "result.jpg";
|
|
||||||
long timeElapsed = 0;
|
long timeElapsed = 0;
|
||||||
long frameCounter = 0;
|
long frameCounter = 0;
|
||||||
|
|
||||||
// Call 'init' and 'release' manually later
|
// Call 'init' and 'release' manually later
|
||||||
PicoDet predictor = new PicoDet();
|
PicoDet predictor = new PicoDet();
|
||||||
|
|
||||||
|
private float[] scores;
|
||||||
|
private int[] labelId;
|
||||||
|
private boolean initialized;
|
||||||
|
private List<String> labelText;
|
||||||
|
private List<BaseResultModel> results = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -124,6 +122,7 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
case R.id.btn_shutter:
|
case R.id.btn_shutter:
|
||||||
TYPE = BTN_SHUTTER;
|
TYPE = BTN_SHUTTER;
|
||||||
shutterAndPauseCamera();
|
shutterAndPauseCamera();
|
||||||
|
resultView.setAdapter(null);
|
||||||
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));
|
||||||
@@ -134,7 +133,7 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
case R.id.back_in_preview:
|
case R.id.back_in_preview:
|
||||||
finish();
|
finish();
|
||||||
break;
|
break;
|
||||||
case R.id.albumSelect:
|
case R.id.iv_select:
|
||||||
TYPE = ALBUM_SELECT;
|
TYPE = ALBUM_SELECT;
|
||||||
// Judge whether authority has been granted.
|
// 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) {
|
||||||
@@ -145,14 +144,32 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
intent.setType("image/*");
|
intent.setType("image/*");
|
||||||
startActivityForResult(intent, INTENT_CODE_PICK_IMAGE);
|
startActivityForResult(intent, INTENT_CODE_PICK_IMAGE);
|
||||||
}
|
}
|
||||||
|
resultView.setAdapter(null);
|
||||||
break;
|
break;
|
||||||
case R.id.back_in_result:
|
case R.id.back_in_result:
|
||||||
|
back();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
super.onBackPressed();
|
||||||
|
back();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void back() {
|
||||||
resultPageView.setVisibility(View.GONE);
|
resultPageView.setVisibility(View.GONE);
|
||||||
cameraPageView.setVisibility(View.VISIBLE);
|
cameraPageView.setVisibility(View.VISIBLE);
|
||||||
TYPE = REALTIME_DETECT;
|
TYPE = REALTIME_DETECT;
|
||||||
isShutterBitmapCopied = false;
|
isShutterBitmapCopied = false;
|
||||||
svPreview.onResume();
|
svPreview.onResume();
|
||||||
break;
|
results.clear();
|
||||||
|
if (scores != null) {
|
||||||
|
scores = null;
|
||||||
|
}
|
||||||
|
if (labelId != null) {
|
||||||
|
labelId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +215,6 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
if (!ARGB8888ImageBitmap.isRecycled()) {
|
if (!ARGB8888ImageBitmap.isRecycled()) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||||
originShutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
||||||
}
|
}
|
||||||
SystemClock.sleep(TIME_SLEEP_INTERVAL);
|
SystemClock.sleep(TIME_SLEEP_INTERVAL);
|
||||||
isShutterBitmapCopied = true;
|
isShutterBitmapCopied = true;
|
||||||
@@ -217,7 +233,6 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
Uri uri = data.getData();
|
Uri uri = data.getData();
|
||||||
String path = getRealPathFromURI(this, uri);
|
String path = getRealPathFromURI(this, uri);
|
||||||
picBitmap = decodeBitmap(path, 720, 1280);
|
picBitmap = decodeBitmap(path, 720, 1280);
|
||||||
originPicBitmap = picBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
||||||
resultImage.setImageBitmap(picBitmap);
|
resultImage.setImageBitmap(picBitmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,27 +263,12 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
copyBitmapFromCamera(ARGB8888ImageBitmap);
|
copyBitmapFromCamera(ARGB8888ImageBitmap);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String savedImagePath = "";
|
|
||||||
synchronized (this) {
|
|
||||||
savedImagePath = Utils.getDCIMDirectory() + File.separator + "result.jpg";
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean modified = false;
|
boolean modified = false;
|
||||||
|
|
||||||
long tc = System.currentTimeMillis();
|
long tc = System.currentTimeMillis();
|
||||||
DetectionResult result = predictor.predict(ARGB8888ImageBitmap);
|
DetectionResult result = predictor.predict(ARGB8888ImageBitmap);
|
||||||
timeElapsed += (System.currentTimeMillis() - tc);
|
timeElapsed += (System.currentTimeMillis() - tc);
|
||||||
|
|
||||||
Visualize.visDetection(ARGB8888ImageBitmap, result, DetectionSettingsActivity.scoreThreshold);
|
Visualize.visDetection(ARGB8888ImageBitmap, result, DetectionSettingsActivity.scoreThreshold);
|
||||||
|
|
||||||
modified = result.initialized();
|
modified = result.initialized();
|
||||||
if (!savedImagePath.isEmpty()) {
|
|
||||||
synchronized (this) {
|
|
||||||
DetectionMainActivity.this.savedImagePath = "result.jpg";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
frameCounter++;
|
frameCounter++;
|
||||||
if (frameCounter >= 30) {
|
if (frameCounter >= 30) {
|
||||||
final int fps = (int) (1000 / (timeElapsed / 30));
|
final int fps = (int) (1000 / (timeElapsed / 30));
|
||||||
@@ -325,7 +325,7 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
realtimeToggleButton.setOnClickListener(this);
|
realtimeToggleButton.setOnClickListener(this);
|
||||||
backInPreview = findViewById(R.id.back_in_preview);
|
backInPreview = findViewById(R.id.back_in_preview);
|
||||||
backInPreview.setOnClickListener(this);
|
backInPreview.setOnClickListener(this);
|
||||||
albumSelectButton = findViewById(R.id.albumSelect);
|
albumSelectButton = findViewById(R.id.iv_select);
|
||||||
albumSelectButton.setOnClickListener(this);
|
albumSelectButton.setOnClickListener(this);
|
||||||
cameraPageView = findViewById(R.id.camera_page);
|
cameraPageView = findViewById(R.id.camera_page);
|
||||||
resultPageView = findViewById(R.id.result_page);
|
resultPageView = findViewById(R.id.result_page);
|
||||||
@@ -334,15 +334,7 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
backInResult.setOnClickListener(this);
|
backInResult.setOnClickListener(this);
|
||||||
confidenceSeekbar = findViewById(R.id.confidence_seekbar);
|
confidenceSeekbar = findViewById(R.id.confidence_seekbar);
|
||||||
seekbarText = findViewById(R.id.seekbar_text);
|
seekbarText = findViewById(R.id.seekbar_text);
|
||||||
detectResultView = findViewById(R.id.result_list_view);
|
resultView = 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.detection_result_page_item, results);
|
|
||||||
detectResultView.setAdapter(adapter);
|
|
||||||
detectResultView.invalidate();
|
|
||||||
|
|
||||||
confidenceSeekbar.setMax(100);
|
confidenceSeekbar.setMax(100);
|
||||||
confidenceSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
confidenceSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
@@ -353,6 +345,7 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
resultNum = bd.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
|
resultNum = bd.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
|
||||||
seekbarText.setText(resultNum + "");
|
seekbarText.setText(resultNum + "");
|
||||||
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
||||||
|
results.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -367,26 +360,46 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (TYPE == ALBUM_SELECT) {
|
if (TYPE == ALBUM_SELECT) {
|
||||||
SystemClock.sleep(TIME_SLEEP_INTERVAL * 10);
|
SystemClock.sleep(TIME_SLEEP_INTERVAL * 10);
|
||||||
if (!picBitmap.isRecycled()) {
|
detail(picBitmap);
|
||||||
predictor.predict(picBitmap, true, resultNum);
|
|
||||||
resultImage.setImageBitmap(picBitmap);
|
|
||||||
picBitmap = originPicBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
||||||
}
|
|
||||||
resultNum = 1.0f;
|
|
||||||
} else {
|
} else {
|
||||||
SystemClock.sleep(TIME_SLEEP_INTERVAL * 10);
|
SystemClock.sleep(TIME_SLEEP_INTERVAL * 10);
|
||||||
if (!shutterBitmap.isRecycled()) {
|
svPreview.onPause();
|
||||||
predictor.predict(shutterBitmap, true, resultNum);
|
detail(shutterBitmap);
|
||||||
resultImage.setImageBitmap(shutterBitmap);
|
|
||||||
shutterBitmap = originShutterBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void detail(Bitmap bitmap) {
|
||||||
|
DetectionResult result = predictor.predict(
|
||||||
|
bitmap, true, DetectionSettingsActivity.scoreThreshold);
|
||||||
|
if (scores == null) {
|
||||||
|
scores = result.mScores;
|
||||||
|
}
|
||||||
|
if (labelId == null) {
|
||||||
|
labelId = result.mLabelIds;
|
||||||
|
}
|
||||||
|
initialized = result.initialized();
|
||||||
|
if (initialized) {
|
||||||
|
for (int i = 0; i < labelId.length; i++) {
|
||||||
|
for (int j = 0; j < labelText.size(); j++) {
|
||||||
|
if (scores[i] > resultNum) {
|
||||||
|
if (labelId[i] == j) {
|
||||||
|
results.add(new BaseResultModel(labelId[i], labelText.get(j), scores[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BaseResultAdapter adapter = new BaseResultAdapter(getBaseContext(), R.layout.ocr_result_page_item, results);
|
||||||
|
resultView.setAdapter(adapter);
|
||||||
|
resultView.invalidate();
|
||||||
|
|
||||||
|
resultImage.setImageBitmap(bitmap);
|
||||||
resultNum = 1.0f;
|
resultNum = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
public void initSettings() {
|
public void initSettings() {
|
||||||
@@ -408,6 +421,7 @@ public class DetectionMainActivity extends Activity implements View.OnClickListe
|
|||||||
String paramsFile = realModelDir + "/" + "model.pdiparams";
|
String paramsFile = realModelDir + "/" + "model.pdiparams";
|
||||||
String configFile = realModelDir + "/" + "infer_cfg.yml";
|
String configFile = realModelDir + "/" + "infer_cfg.yml";
|
||||||
String labelFile = realLabelPath;
|
String labelFile = realLabelPath;
|
||||||
|
labelText = readTxt(labelFile);
|
||||||
RuntimeOption option = new RuntimeOption();
|
RuntimeOption option = new RuntimeOption();
|
||||||
option.setCpuThreadNum(DetectionSettingsActivity.cpuThreadNum);
|
option.setCpuThreadNum(DetectionSettingsActivity.cpuThreadNum);
|
||||||
option.setLitePowerMode(DetectionSettingsActivity.cpuPowerMode);
|
option.setLitePowerMode(DetectionSettingsActivity.cpuPowerMode);
|
||||||
|
@@ -8,14 +8,11 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.provider.MediaStore;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
@@ -43,7 +40,6 @@ 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.decodeBitmap;
|
||||||
import static com.baidu.paddle.fastdeploy.app.ui.Utils.getRealPathFromURI;
|
import static com.baidu.paddle.fastdeploy.app.ui.Utils.getRealPathFromURI;
|
||||||
|
|
||||||
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;
|
||||||
@@ -67,11 +63,9 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
|
|||||||
private SeekBar confidenceSeekbar;
|
private SeekBar confidenceSeekbar;
|
||||||
private TextView seekbarText;
|
private TextView seekbarText;
|
||||||
private float resultNum = 1.0f;
|
private float resultNum = 1.0f;
|
||||||
private ResultListView detectResultView;
|
private ResultListView resultView;
|
||||||
private Bitmap shutterBitmap;
|
private Bitmap shutterBitmap;
|
||||||
private Bitmap originShutterBitmap;
|
|
||||||
private Bitmap picBitmap;
|
private Bitmap picBitmap;
|
||||||
private Bitmap originPicBitmap;
|
|
||||||
private boolean isShutterBitmapCopied = false;
|
private boolean isShutterBitmapCopied = false;
|
||||||
|
|
||||||
public static final int TYPE_UNKNOWN = -1;
|
public static final int TYPE_UNKNOWN = -1;
|
||||||
@@ -84,13 +78,16 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
|
|||||||
private static final int INTENT_CODE_PICK_IMAGE = 100;
|
private static final int INTENT_CODE_PICK_IMAGE = 100;
|
||||||
private static final int TIME_SLEEP_INTERVAL = 50; // ms
|
private static final int TIME_SLEEP_INTERVAL = 50; // ms
|
||||||
|
|
||||||
String savedImagePath = "result.jpg";
|
|
||||||
long timeElapsed = 0;
|
long timeElapsed = 0;
|
||||||
long frameCounter = 0;
|
long frameCounter = 0;
|
||||||
|
|
||||||
// Call 'init' and 'release' manually later
|
// Call 'init' and 'release' manually later
|
||||||
SCRFD predictor = new SCRFD();
|
SCRFD predictor = new SCRFD();
|
||||||
|
|
||||||
|
public float[] scores; // [n]
|
||||||
|
public boolean initialized = false;
|
||||||
|
private List<BaseResultModel> results = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -123,6 +120,7 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
|
|||||||
case R.id.btn_shutter:
|
case R.id.btn_shutter:
|
||||||
TYPE = BTN_SHUTTER;
|
TYPE = BTN_SHUTTER;
|
||||||
shutterAndPauseCamera();
|
shutterAndPauseCamera();
|
||||||
|
resultView.setAdapter(null);
|
||||||
break;
|
break;
|
||||||
case R.id.btn_settings:
|
case R.id.btn_settings:
|
||||||
startActivity(new Intent(FaceDetMainActivity.this, FaceDetSettingsActivity.class));
|
startActivity(new Intent(FaceDetMainActivity.this, FaceDetSettingsActivity.class));
|
||||||
@@ -144,14 +142,29 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
|
|||||||
intent.setType("image/*");
|
intent.setType("image/*");
|
||||||
startActivityForResult(intent, INTENT_CODE_PICK_IMAGE);
|
startActivityForResult(intent, INTENT_CODE_PICK_IMAGE);
|
||||||
}
|
}
|
||||||
|
resultView.setAdapter(null);
|
||||||
break;
|
break;
|
||||||
case R.id.back_in_result:
|
case R.id.back_in_result:
|
||||||
|
back();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
super.onBackPressed();
|
||||||
|
back();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void back() {
|
||||||
resultPageView.setVisibility(View.GONE);
|
resultPageView.setVisibility(View.GONE);
|
||||||
cameraPageView.setVisibility(View.VISIBLE);
|
cameraPageView.setVisibility(View.VISIBLE);
|
||||||
TYPE = REALTIME_DETECT;
|
TYPE = REALTIME_DETECT;
|
||||||
isShutterBitmapCopied = false;
|
isShutterBitmapCopied = false;
|
||||||
svPreview.onResume();
|
svPreview.onResume();
|
||||||
break;
|
results.clear();
|
||||||
|
if (scores != null) {
|
||||||
|
scores = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +210,6 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
|
|||||||
if (!ARGB8888ImageBitmap.isRecycled()) {
|
if (!ARGB8888ImageBitmap.isRecycled()) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||||
originShutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
||||||
}
|
}
|
||||||
SystemClock.sleep(TIME_SLEEP_INTERVAL);
|
SystemClock.sleep(TIME_SLEEP_INTERVAL);
|
||||||
isShutterBitmapCopied = true;
|
isShutterBitmapCopied = true;
|
||||||
@@ -216,7 +228,6 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
|
|||||||
Uri uri = data.getData();
|
Uri uri = data.getData();
|
||||||
String path = getRealPathFromURI(this, uri);
|
String path = getRealPathFromURI(this, uri);
|
||||||
picBitmap = decodeBitmap(path, 720, 1280);
|
picBitmap = decodeBitmap(path, 720, 1280);
|
||||||
originPicBitmap = picBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
||||||
resultImage.setImageBitmap(picBitmap);
|
resultImage.setImageBitmap(picBitmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,29 +259,14 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
|
|||||||
copyBitmapFromCamera(ARGB8888ImageBitmap);
|
copyBitmapFromCamera(ARGB8888ImageBitmap);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String savedImagePath = "";
|
|
||||||
synchronized (this) {
|
|
||||||
savedImagePath = Utils.getDCIMDirectory() + File.separator + "result.jpg";
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean modified = false;
|
boolean modified = false;
|
||||||
|
|
||||||
long tc = System.currentTimeMillis();
|
long tc = System.currentTimeMillis();
|
||||||
|
SystemClock.sleep(TIME_SLEEP_INTERVAL);
|
||||||
FaceDetectionResult result = predictor.predict(
|
FaceDetectionResult result = predictor.predict(
|
||||||
ARGB8888ImageBitmap, FaceDetSettingsActivity.scoreThreshold, 0.4f);
|
ARGB8888ImageBitmap, FaceDetSettingsActivity.scoreThreshold, 0.4f);
|
||||||
|
|
||||||
timeElapsed += (System.currentTimeMillis() - tc);
|
timeElapsed += (System.currentTimeMillis() - tc);
|
||||||
|
|
||||||
Visualize.visFaceDetection(ARGB8888ImageBitmap, result);
|
Visualize.visFaceDetection(ARGB8888ImageBitmap, result);
|
||||||
|
|
||||||
modified = result.initialized();
|
modified = result.initialized();
|
||||||
if (!savedImagePath.isEmpty()) {
|
|
||||||
synchronized (this) {
|
|
||||||
FaceDetMainActivity.this.savedImagePath = "result.jpg";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
frameCounter++;
|
frameCounter++;
|
||||||
if (frameCounter >= 30) {
|
if (frameCounter >= 30) {
|
||||||
final int fps = (int) (1000 / (timeElapsed / 30));
|
final int fps = (int) (1000 / (timeElapsed / 30));
|
||||||
@@ -336,16 +332,7 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
|
|||||||
backInResult.setOnClickListener(this);
|
backInResult.setOnClickListener(this);
|
||||||
confidenceSeekbar = findViewById(R.id.confidence_seekbar);
|
confidenceSeekbar = findViewById(R.id.confidence_seekbar);
|
||||||
seekbarText = findViewById(R.id.seekbar_text);
|
seekbarText = findViewById(R.id.seekbar_text);
|
||||||
detectResultView = findViewById(R.id.result_list_view);
|
resultView = 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.setMax(100);
|
||||||
confidenceSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
confidenceSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
@@ -356,6 +343,7 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
|
|||||||
resultNum = bd.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
|
resultNum = bd.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
|
||||||
seekbarText.setText(resultNum + "");
|
seekbarText.setText(resultNum + "");
|
||||||
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
||||||
|
results.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -370,26 +358,39 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (TYPE == ALBUM_SELECT) {
|
if (TYPE == ALBUM_SELECT) {
|
||||||
SystemClock.sleep(TIME_SLEEP_INTERVAL * 10); // 500ms
|
SystemClock.sleep(TIME_SLEEP_INTERVAL * 10); // 500ms
|
||||||
if (!picBitmap.isRecycled()) {
|
detail(picBitmap);
|
||||||
predictor.predict(picBitmap, true, resultNum, 0.4f);
|
|
||||||
resultImage.setImageBitmap(picBitmap);
|
|
||||||
picBitmap = originPicBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
||||||
}
|
|
||||||
resultNum = 1.0f;
|
|
||||||
} else {
|
} else {
|
||||||
SystemClock.sleep(TIME_SLEEP_INTERVAL * 10); // 500ms
|
SystemClock.sleep(TIME_SLEEP_INTERVAL * 10); // 500ms
|
||||||
if (!shutterBitmap.isRecycled()) {
|
svPreview.onPause();
|
||||||
predictor.predict(shutterBitmap, true, resultNum, 0.4f);
|
detail(shutterBitmap);
|
||||||
resultImage.setImageBitmap(shutterBitmap);
|
|
||||||
shutterBitmap = originShutterBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void detail(Bitmap bitmap) {
|
||||||
|
FaceDetectionResult result = predictor.predict(bitmap, true, FaceDetSettingsActivity.scoreThreshold, 0.4f);
|
||||||
|
if (scores == null) {
|
||||||
|
scores = result.mScores;
|
||||||
|
}
|
||||||
|
initialized = result.initialized();
|
||||||
|
Log.e("GBD", initialized + "---initialized");
|
||||||
|
if (initialized) {
|
||||||
|
for (int i = 0; i < scores.length; i++) {
|
||||||
|
if (scores[i] > resultNum) {
|
||||||
|
results.add(new BaseResultModel(i + 1, "face", scores[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BaseResultAdapter adapter = new BaseResultAdapter(getBaseContext(), R.layout.ocr_result_page_item, results);
|
||||||
|
resultView.setAdapter(adapter);
|
||||||
|
resultView.invalidate();
|
||||||
|
|
||||||
|
resultImage.setImageBitmap(bitmap);
|
||||||
resultNum = 1.0f;
|
resultNum = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
public void initSettings() {
|
public void initSettings() {
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
package com.baidu.paddle.fastdeploy.app.examples.ocr;
|
package com.baidu.paddle.fastdeploy.app.examples.ocr;
|
||||||
|
|
||||||
|
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;
|
||||||
@@ -10,32 +12,39 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
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.ui.Utils;
|
|
||||||
import com.baidu.paddle.fastdeploy.app.ui.view.CameraSurfaceView;
|
import com.baidu.paddle.fastdeploy.app.ui.view.CameraSurfaceView;
|
||||||
import com.baidu.paddle.fastdeploy.vision.OCRResult;
|
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.pipeline.PPOCRv2;
|
import com.baidu.paddle.fastdeploy.pipeline.PPOCRv2;
|
||||||
|
import com.baidu.paddle.fastdeploy.vision.OCRResult;
|
||||||
|
import com.baidu.paddle.fastdeploy.vision.Visualize;
|
||||||
import com.baidu.paddle.fastdeploy.vision.ocr.Classifier;
|
import com.baidu.paddle.fastdeploy.vision.ocr.Classifier;
|
||||||
import com.baidu.paddle.fastdeploy.vision.ocr.DBDetector;
|
import com.baidu.paddle.fastdeploy.vision.ocr.DBDetector;
|
||||||
import com.baidu.paddle.fastdeploy.vision.ocr.Recognizer;
|
import com.baidu.paddle.fastdeploy.vision.ocr.Recognizer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.math.BigDecimal;
|
||||||
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.List;
|
||||||
|
|
||||||
public class OcrMainActivity extends Activity implements View.OnClickListener, CameraSurfaceView.OnTextureChangedListener {
|
public class OcrMainActivity extends Activity implements View.OnClickListener, CameraSurfaceView.OnTextureChangedListener {
|
||||||
private static final String TAG = OcrMainActivity.class.getSimpleName();
|
private static final String TAG = OcrMainActivity.class.getSimpleName();
|
||||||
@@ -48,14 +57,40 @@ public class OcrMainActivity extends Activity implements View.OnClickListener, C
|
|||||||
ImageView realtimeToggleButton;
|
ImageView realtimeToggleButton;
|
||||||
boolean isRealtimeStatusRunning = false;
|
boolean isRealtimeStatusRunning = false;
|
||||||
ImageView backInPreview;
|
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 resultView;
|
||||||
|
private Bitmap shutterBitmap;
|
||||||
|
private Bitmap picBitmap;
|
||||||
|
private boolean isShutterBitmapCopied = false;
|
||||||
|
|
||||||
String savedImagePath = "result.jpg";
|
public static final int TYPE_UNKNOWN = -1;
|
||||||
int lastFrameIndex = 0;
|
public static final int BTN_SHUTTER = 0;
|
||||||
long lastFrameTime;
|
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
|
||||||
|
|
||||||
|
long timeElapsed = 0;
|
||||||
|
long frameCounter = 0;
|
||||||
|
|
||||||
// Call 'init' and 'release' manually later
|
// Call 'init' and 'release' manually later
|
||||||
PPOCRv2 predictor = new PPOCRv2();
|
PPOCRv2 predictor = new PPOCRv2();
|
||||||
|
|
||||||
|
private String[] texts;
|
||||||
|
private float[] recScores;
|
||||||
|
private boolean initialized;
|
||||||
|
private List<BaseResultModel> results = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -86,12 +121,9 @@ public class OcrMainActivity extends Activity implements View.OnClickListener, C
|
|||||||
svPreview.switchCamera();
|
svPreview.switchCamera();
|
||||||
break;
|
break;
|
||||||
case R.id.btn_shutter:
|
case R.id.btn_shutter:
|
||||||
@SuppressLint("SimpleDateFormat")
|
TYPE = BTN_SHUTTER;
|
||||||
SimpleDateFormat date = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
|
shutterAndPauseCamera();
|
||||||
synchronized (this) {
|
resultView.setAdapter(null);
|
||||||
savedImagePath = Utils.getDCIMDirectory() + File.separator + date.format(new Date()).toString() + ".png";
|
|
||||||
}
|
|
||||||
Toast.makeText(OcrMainActivity.this, "Save snapshot to " + savedImagePath, Toast.LENGTH_SHORT).show();
|
|
||||||
break;
|
break;
|
||||||
case R.id.btn_settings:
|
case R.id.btn_settings:
|
||||||
startActivity(new Intent(OcrMainActivity.this, OcrSettingsActivity.class));
|
startActivity(new Intent(OcrMainActivity.this, OcrSettingsActivity.class));
|
||||||
@@ -102,6 +134,109 @@ public class OcrMainActivity extends Activity implements View.OnClickListener, C
|
|||||||
case R.id.back_in_preview:
|
case R.id.back_in_preview:
|
||||||
finish();
|
finish();
|
||||||
break;
|
break;
|
||||||
|
case R.id.iv_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);
|
||||||
|
}
|
||||||
|
resultView.setAdapter(null);
|
||||||
|
break;
|
||||||
|
case R.id.back_in_result:
|
||||||
|
back();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
super.onBackPressed();
|
||||||
|
back();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void back() {
|
||||||
|
resultPageView.setVisibility(View.GONE);
|
||||||
|
cameraPageView.setVisibility(View.VISIBLE);
|
||||||
|
TYPE = REALTIME_DETECT;
|
||||||
|
isShutterBitmapCopied = false;
|
||||||
|
svPreview.onResume();
|
||||||
|
results.clear();
|
||||||
|
if (texts != null) {
|
||||||
|
texts = null;
|
||||||
|
}
|
||||||
|
if (recScores != null) {
|
||||||
|
recScores = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 * 10); // 500ms
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
public void run() {
|
||||||
|
// These code will run in main thread.
|
||||||
|
svPreview.onPause();
|
||||||
|
cameraPageView.setVisibility(View.GONE);
|
||||||
|
resultPageView.setVisibility(View.VISIBLE);
|
||||||
|
seekbarText.setText(resultNum + "");
|
||||||
|
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
||||||
|
if (shutterBitmap != null && !shutterBitmap.isRecycled()) {
|
||||||
|
resultImage.setImageBitmap(shutterBitmap);
|
||||||
|
} else {
|
||||||
|
new AlertDialog.Builder(OcrMainActivity.this)
|
||||||
|
.setTitle("Empty Result!")
|
||||||
|
.setMessage("Current picture is empty, please shutting it again!")
|
||||||
|
.setCancelable(true)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void copyBitmapFromCamera(Bitmap ARGB8888ImageBitmap) {
|
||||||
|
if (isShutterBitmapCopied || ARGB8888ImageBitmap == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!ARGB8888ImageBitmap.isRecycled()) {
|
||||||
|
synchronized (this) {
|
||||||
|
shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||||
|
}
|
||||||
|
SystemClock.sleep(TIME_SLEEP_INTERVAL);
|
||||||
|
isShutterBitmapCopied = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@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);
|
||||||
|
resultImage.setImageBitmap(picBitmap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,29 +261,27 @@ public class OcrMainActivity extends Activity implements View.OnClickListener, C
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTextureChanged(Bitmap ARGB8888ImageBitmap) {
|
public boolean onTextureChanged(Bitmap ARGB8888ImageBitmap) {
|
||||||
String savedImagePath = "";
|
if (TYPE == BTN_SHUTTER) {
|
||||||
synchronized (this) {
|
copyBitmapFromCamera(ARGB8888ImageBitmap);
|
||||||
savedImagePath = OcrMainActivity.this.savedImagePath;
|
return false;
|
||||||
}
|
}
|
||||||
boolean modified = false;
|
boolean modified = false;
|
||||||
OCRResult result = predictor.predict(ARGB8888ImageBitmap, savedImagePath);
|
long tc = System.currentTimeMillis();
|
||||||
|
OCRResult result = predictor.predict(ARGB8888ImageBitmap, true);
|
||||||
|
timeElapsed += (System.currentTimeMillis() - tc);
|
||||||
|
Visualize.visOcr(ARGB8888ImageBitmap, result);
|
||||||
modified = result.initialized();
|
modified = result.initialized();
|
||||||
if (!savedImagePath.isEmpty()) {
|
frameCounter++;
|
||||||
synchronized (this) {
|
if (frameCounter >= 30) {
|
||||||
OcrMainActivity.this.savedImagePath = "result.jpg";
|
final int fps = (int) (1000 / (timeElapsed / 30));
|
||||||
}
|
|
||||||
}
|
|
||||||
lastFrameIndex++;
|
|
||||||
if (lastFrameIndex >= 30) {
|
|
||||||
final int fps = (int) (lastFrameIndex * 1e9 / (System.nanoTime() - lastFrameTime));
|
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
public void run() {
|
public void run() {
|
||||||
tvStatus.setText(Integer.toString(fps) + "fps");
|
tvStatus.setText(Integer.toString(fps) + "fps");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
lastFrameIndex = 0;
|
frameCounter = 0;
|
||||||
lastFrameTime = System.nanoTime();
|
timeElapsed = 0;
|
||||||
}
|
}
|
||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
@@ -180,6 +313,7 @@ public class OcrMainActivity extends Activity implements View.OnClickListener, C
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initView() {
|
public void initView() {
|
||||||
|
TYPE = REALTIME_DETECT;
|
||||||
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);
|
||||||
@@ -193,6 +327,75 @@ public class OcrMainActivity extends Activity implements View.OnClickListener, C
|
|||||||
realtimeToggleButton.setOnClickListener(this);
|
realtimeToggleButton.setOnClickListener(this);
|
||||||
backInPreview = findViewById(R.id.back_in_preview);
|
backInPreview = findViewById(R.id.back_in_preview);
|
||||||
backInPreview.setOnClickListener(this);
|
backInPreview.setOnClickListener(this);
|
||||||
|
albumSelectButton = findViewById(R.id.iv_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);
|
||||||
|
resultView = findViewById(R.id.result_list_view);
|
||||||
|
|
||||||
|
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));
|
||||||
|
results.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
detail(picBitmap);
|
||||||
|
} else {
|
||||||
|
SystemClock.sleep(TIME_SLEEP_INTERVAL * 10);
|
||||||
|
svPreview.onPause();
|
||||||
|
detail(shutterBitmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void detail(Bitmap bitmap) {
|
||||||
|
OCRResult result = predictor.predict(bitmap, true);
|
||||||
|
if (texts == null) {
|
||||||
|
texts = result.mText;
|
||||||
|
}
|
||||||
|
if (recScores == null) {
|
||||||
|
recScores = result.mRecScores;
|
||||||
|
}
|
||||||
|
initialized = result.initialized();
|
||||||
|
if (initialized) {
|
||||||
|
for (int i = 0; i < texts.length; i++) {
|
||||||
|
if (recScores[i] > resultNum) {
|
||||||
|
results.add(new BaseResultModel(i + 1, texts[i], recScores[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BaseResultAdapter adapter = new BaseResultAdapter(getBaseContext(), R.layout.ocr_result_page_item, results);
|
||||||
|
resultView.setAdapter(adapter);
|
||||||
|
resultView.invalidate();
|
||||||
|
|
||||||
|
resultImage.setImageBitmap(bitmap);
|
||||||
|
resultNum = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
|
@@ -1,8 +1,5 @@
|
|||||||
package com.baidu.paddle.fastdeploy.app.examples.segmentation;
|
package com.baidu.paddle.fastdeploy.app.examples.segmentation;
|
||||||
|
|
||||||
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;
|
||||||
@@ -31,16 +28,17 @@ 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.ui.Utils;
|
|
||||||
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.view.adapter.BaseResultAdapter;
|
import com.baidu.paddle.fastdeploy.app.ui.Utils;
|
||||||
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.SegmentationResult;
|
import com.baidu.paddle.fastdeploy.vision.SegmentationResult;
|
||||||
import com.baidu.paddle.fastdeploy.vision.Visualize;
|
import com.baidu.paddle.fastdeploy.vision.Visualize;
|
||||||
import com.baidu.paddle.fastdeploy.vision.segmentation.PaddleSegModel;
|
import com.baidu.paddle.fastdeploy.vision.segmentation.PaddleSegModel;
|
||||||
|
|
||||||
import java.io.File;
|
import static com.baidu.paddle.fastdeploy.app.ui.Utils.decodeBitmap;
|
||||||
|
import static com.baidu.paddle.fastdeploy.app.ui.Utils.getRealPathFromURI;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -64,11 +62,9 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
private SeekBar confidenceSeekbar;
|
private SeekBar confidenceSeekbar;
|
||||||
private TextView seekbarText;
|
private TextView seekbarText;
|
||||||
private float resultNum = 1.0f;
|
private float resultNum = 1.0f;
|
||||||
private ResultListView detectResultView;
|
private ResultListView resultView;
|
||||||
private Bitmap shutterBitmap;
|
private Bitmap shutterBitmap;
|
||||||
private Bitmap originShutterBitmap;
|
|
||||||
private Bitmap picBitmap;
|
private Bitmap picBitmap;
|
||||||
private Bitmap originPicBitmap;
|
|
||||||
private boolean isShutterBitmapCopied = false;
|
private boolean isShutterBitmapCopied = false;
|
||||||
|
|
||||||
public static final int TYPE_UNKNOWN = -1;
|
public static final int TYPE_UNKNOWN = -1;
|
||||||
@@ -81,12 +77,12 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
private static final int INTENT_CODE_PICK_IMAGE = 100;
|
private static final int INTENT_CODE_PICK_IMAGE = 100;
|
||||||
private static final int TIME_SLEEP_INTERVAL = 50; // ms
|
private static final int TIME_SLEEP_INTERVAL = 50; // ms
|
||||||
|
|
||||||
String savedImagePath = "result.jpg";
|
|
||||||
long timeElapsed = 0;
|
long timeElapsed = 0;
|
||||||
long frameCounter = 0;
|
long frameCounter = 0;
|
||||||
|
|
||||||
// Call 'init' and 'release' manually later
|
// Call 'init' and 'release' manually later
|
||||||
PaddleSegModel predictor = new PaddleSegModel();
|
PaddleSegModel predictor = new PaddleSegModel();
|
||||||
|
private List<BaseResultModel> results = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -120,6 +116,7 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
case R.id.btn_shutter:
|
case R.id.btn_shutter:
|
||||||
TYPE = BTN_SHUTTER;
|
TYPE = BTN_SHUTTER;
|
||||||
shutterAndPauseCamera();
|
shutterAndPauseCamera();
|
||||||
|
resultView.setAdapter(null);
|
||||||
break;
|
break;
|
||||||
case R.id.btn_settings:
|
case R.id.btn_settings:
|
||||||
startActivity(new Intent(SegmentationMainActivity.this, SegmentationSettingsActivity.class));
|
startActivity(new Intent(SegmentationMainActivity.this, SegmentationSettingsActivity.class));
|
||||||
@@ -141,15 +138,27 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
intent.setType("image/*");
|
intent.setType("image/*");
|
||||||
startActivityForResult(intent, INTENT_CODE_PICK_IMAGE);
|
startActivityForResult(intent, INTENT_CODE_PICK_IMAGE);
|
||||||
}
|
}
|
||||||
|
resultView.setAdapter(null);
|
||||||
break;
|
break;
|
||||||
case R.id.back_in_result:
|
case R.id.back_in_result:
|
||||||
|
back();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
super.onBackPressed();
|
||||||
|
back();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void back() {
|
||||||
resultPageView.setVisibility(View.GONE);
|
resultPageView.setVisibility(View.GONE);
|
||||||
cameraPageView.setVisibility(View.VISIBLE);
|
cameraPageView.setVisibility(View.VISIBLE);
|
||||||
TYPE = REALTIME_DETECT;
|
TYPE = REALTIME_DETECT;
|
||||||
isShutterBitmapCopied = false;
|
isShutterBitmapCopied = false;
|
||||||
svPreview.onResume();
|
svPreview.onResume();
|
||||||
break;
|
results.clear();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shutterAndPauseCamera() {
|
private void shutterAndPauseCamera() {
|
||||||
@@ -172,7 +181,7 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
seekbarText.setText(resultNum + "");
|
seekbarText.setText(resultNum + "");
|
||||||
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
||||||
if (shutterBitmap != null && !shutterBitmap.isRecycled()) {
|
if (shutterBitmap != null && !shutterBitmap.isRecycled()) {
|
||||||
resultImage.setImageBitmap(shutterBitmap);
|
detail(shutterBitmap);
|
||||||
} else {
|
} else {
|
||||||
new AlertDialog.Builder(SegmentationMainActivity.this)
|
new AlertDialog.Builder(SegmentationMainActivity.this)
|
||||||
.setTitle("Empty Result!")
|
.setTitle("Empty Result!")
|
||||||
@@ -193,7 +202,6 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
if (!ARGB8888ImageBitmap.isRecycled()) {
|
if (!ARGB8888ImageBitmap.isRecycled()) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||||
originShutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
||||||
}
|
}
|
||||||
SystemClock.sleep(TIME_SLEEP_INTERVAL);
|
SystemClock.sleep(TIME_SLEEP_INTERVAL);
|
||||||
isShutterBitmapCopied = true;
|
isShutterBitmapCopied = true;
|
||||||
@@ -211,9 +219,10 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
||||||
Uri uri = data.getData();
|
Uri uri = data.getData();
|
||||||
String path = getRealPathFromURI(this, uri);
|
String path = getRealPathFromURI(this, uri);
|
||||||
picBitmap = decodeBitmap(path, 720, 1280);
|
Bitmap bitmap = decodeBitmap(path, 720, 1280);
|
||||||
originPicBitmap = picBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
picBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||||
resultImage.setImageBitmap(picBitmap);
|
SystemClock.sleep(TIME_SLEEP_INTERVAL * 10); // 500ms
|
||||||
|
detail(picBitmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,27 +253,12 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
copyBitmapFromCamera(ARGB8888ImageBitmap);
|
copyBitmapFromCamera(ARGB8888ImageBitmap);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String savedImagePath = "";
|
|
||||||
synchronized (this) {
|
|
||||||
savedImagePath = Utils.getDCIMDirectory() + File.separator + "result.jpg";
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean modified = false;
|
boolean modified = false;
|
||||||
|
|
||||||
long tc = System.currentTimeMillis();
|
long tc = System.currentTimeMillis();
|
||||||
SegmentationResult result = predictor.predict(ARGB8888ImageBitmap);
|
SegmentationResult result = predictor.predict(ARGB8888ImageBitmap);
|
||||||
timeElapsed += (System.currentTimeMillis() - tc);
|
timeElapsed += (System.currentTimeMillis() - tc);
|
||||||
|
|
||||||
Visualize.visSegmentation(ARGB8888ImageBitmap, result);
|
Visualize.visSegmentation(ARGB8888ImageBitmap, result);
|
||||||
|
|
||||||
modified = result.initialized();
|
modified = result.initialized();
|
||||||
if (!savedImagePath.isEmpty()) {
|
|
||||||
synchronized (this) {
|
|
||||||
SegmentationMainActivity.this.savedImagePath = "result.jpg";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
frameCounter++;
|
frameCounter++;
|
||||||
if (frameCounter >= 30) {
|
if (frameCounter >= 30) {
|
||||||
final int fps = (int) (1000 / (timeElapsed / 30));
|
final int fps = (int) (1000 / (timeElapsed / 30));
|
||||||
@@ -308,16 +302,8 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
|
|
||||||
public void initView() {
|
public void initView() {
|
||||||
TYPE = REALTIME_DETECT;
|
TYPE = REALTIME_DETECT;
|
||||||
// For front face camera and human seg, the smaller width and height
|
|
||||||
// may get both better result and performance. EXPECTED_PREVIEW_HEIGHT
|
|
||||||
// should be 'width' and EXPECTED_PREVIEW_WIDTH should be 'height' if
|
|
||||||
// your camera display orientation is rotate (degree == 90 || degree == 270).
|
|
||||||
// The transformation will auto process in camera.
|
|
||||||
CameraSurfaceView.EXPECTED_PREVIEW_HEIGHT = 360;
|
|
||||||
CameraSurfaceView.EXPECTED_PREVIEW_WIDTH = 720;
|
|
||||||
svPreview = (CameraSurfaceView) findViewById(R.id.sv_preview);
|
svPreview = (CameraSurfaceView) findViewById(R.id.sv_preview);
|
||||||
svPreview.setOnTextureChangedListener(this);
|
svPreview.setOnTextureChangedListener(this);
|
||||||
svPreview.switchCamera(); // switch to front camera for human seg
|
|
||||||
tvStatus = (TextView) findViewById(R.id.tv_status);
|
tvStatus = (TextView) findViewById(R.id.tv_status);
|
||||||
btnSwitch = (ImageButton) findViewById(R.id.btn_switch);
|
btnSwitch = (ImageButton) findViewById(R.id.btn_switch);
|
||||||
btnSwitch.setOnClickListener(this);
|
btnSwitch.setOnClickListener(this);
|
||||||
@@ -338,16 +324,7 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
backInResult.setOnClickListener(this);
|
backInResult.setOnClickListener(this);
|
||||||
confidenceSeekbar = findViewById(R.id.confidence_seekbar);
|
confidenceSeekbar = findViewById(R.id.confidence_seekbar);
|
||||||
seekbarText = findViewById(R.id.seekbar_text);
|
seekbarText = findViewById(R.id.seekbar_text);
|
||||||
detectResultView = findViewById(R.id.result_list_view);
|
resultView = findViewById(R.id.result_list_view);
|
||||||
|
|
||||||
List<BaseResultModel> results = new ArrayList<>();
|
|
||||||
// TODO: add model results from SegmentationResult instead of using fake data.
|
|
||||||
results.add(new BaseResultModel(1, "human", 1.0f));
|
|
||||||
results.add(new BaseResultModel(2, "human", 1.0f));
|
|
||||||
results.add(new BaseResultModel(3, "human", 1.0f));
|
|
||||||
final BaseResultAdapter adapter = new BaseResultAdapter(this, R.layout.facedet_result_page_item, results);
|
|
||||||
detectResultView.setAdapter(adapter);
|
|
||||||
detectResultView.invalidate();
|
|
||||||
|
|
||||||
confidenceSeekbar.setMax(100);
|
confidenceSeekbar.setMax(100);
|
||||||
confidenceSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
confidenceSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
@@ -358,6 +335,7 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
resultNum = bd.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
|
resultNum = bd.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
|
||||||
seekbarText.setText(resultNum + "");
|
seekbarText.setText(resultNum + "");
|
||||||
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
||||||
|
results.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -367,30 +345,27 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
runOnUiThread(new Runnable() {
|
// runOnUiThread(new Runnable() {
|
||||||
@Override
|
// @Override
|
||||||
public void run() {
|
// public void run() {
|
||||||
if (TYPE == ALBUM_SELECT) {
|
// if (TYPE == ALBUM_SELECT) {
|
||||||
SystemClock.sleep(TIME_SLEEP_INTERVAL * 10); // 500ms
|
// SystemClock.sleep(TIME_SLEEP_INTERVAL * 10); // 500ms
|
||||||
if (!picBitmap.isRecycled()) {
|
// detail(picBitmap);
|
||||||
predictor.predict(picBitmap, true, resultNum);
|
// } else {
|
||||||
resultImage.setImageBitmap(picBitmap);
|
// SystemClock.sleep(TIME_SLEEP_INTERVAL * 10); // 500ms
|
||||||
picBitmap = originPicBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
// svPreview.onPause();
|
||||||
}
|
// detail(shutterBitmap);
|
||||||
resultNum = 1.0f;
|
// }
|
||||||
} else {
|
// }
|
||||||
SystemClock.sleep(TIME_SLEEP_INTERVAL * 10); // 500ms
|
// });
|
||||||
if (!shutterBitmap.isRecycled()) {
|
|
||||||
predictor.predict(shutterBitmap, true, resultNum);
|
|
||||||
resultImage.setImageBitmap(shutterBitmap);
|
|
||||||
shutterBitmap = originShutterBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
||||||
}
|
|
||||||
resultNum = 1.0f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
private void detail(Bitmap bitmap) {
|
||||||
|
predictor.predict(bitmap, true, 0.6f);
|
||||||
|
resultImage.setImageBitmap(bitmap);
|
||||||
|
resultNum = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
@@ -448,32 +423,5 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
return ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
|
return ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
|
||||||
&& ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
|
&& ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -16,12 +16,16 @@ import android.view.WindowManager;
|
|||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
@@ -286,4 +290,24 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> readTxt(String txtPath) {
|
||||||
|
File file = new File(txtPath);
|
||||||
|
if (file.isFile() && file.exists()) {
|
||||||
|
try {
|
||||||
|
FileInputStream fileInputStream = new FileInputStream(file);
|
||||||
|
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
||||||
|
String text;
|
||||||
|
List<String> labels = new ArrayList<>();
|
||||||
|
while ((text = bufferedReader.readLine()) != null) {
|
||||||
|
labels.add(text);
|
||||||
|
}
|
||||||
|
return labels;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -64,7 +64,7 @@
|
|||||||
android:layout_centerInParent="true" />
|
android:layout_centerInParent="true" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/albumSelect"
|
android:id="@+id/iv_select"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="40dp"
|
android:layout_height="40dp"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
@@ -62,7 +62,7 @@
|
|||||||
android:layout_centerInParent="true" />
|
android:layout_centerInParent="true" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/albumSelect"
|
android:id="@+id/iv_select"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="40dp"
|
android:layout_height="40dp"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
@@ -47,14 +47,13 @@
|
|||||||
<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.layout.ActionBarLayout>
|
</com.baidu.paddle.fastdeploy.app.ui.layout.ActionBarLayout>
|
||||||
|
|
||||||
<!-- 实时-->
|
|
||||||
<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"
|
||||||
@@ -64,7 +63,7 @@
|
|||||||
android:layout_centerInParent="true" />
|
android:layout_centerInParent="true" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/albumSelect"
|
android:id="@+id/iv_select"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="40dp"
|
android:layout_height="40dp"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
Reference in New Issue
Block a user