mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-04 16:22:57 +08:00
[Android] Update fastdeploy Android app ui module (#531)
Revert "[Android] Revert update fastdeploy Android app ui module (#530)"
This reverts commit 628b2d130d
.
This commit is contained in:
@@ -15,14 +15,14 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name="com.baidu.paddle.fastdeploy.app.examples.ocr.MainActivity">
|
||||
<activity android:name=".ocr.OcrMainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.baidu.paddle.fastdeploy.app.examples.ocr.SettingsActivity"
|
||||
android:name=".ocr.OcrSettingsActivity"
|
||||
android:label="Settings">
|
||||
</activity>
|
||||
</application>
|
||||
|
@@ -0,0 +1,431 @@
|
||||
package com.baidu.paddle.fastdeploy.app.examples.detection;
|
||||
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.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.DetectResultAdapter;
|
||||
import com.baidu.paddle.fastdeploy.app.ui.view.model.BaseResultModel;
|
||||
import com.baidu.paddle.fastdeploy.vision.DetectionResult;
|
||||
import com.baidu.paddle.fastdeploy.vision.detection.PicoDet;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DetectionMainActivity extends Activity implements View.OnClickListener, CameraSurfaceView.OnTextureChangedListener {
|
||||
private static final String TAG = DetectionMainActivity.class.getSimpleName();
|
||||
|
||||
CameraSurfaceView svPreview;
|
||||
TextView tvStatus;
|
||||
ImageButton btnSwitch;
|
||||
ImageButton btnShutter;
|
||||
ImageButton btnSettings;
|
||||
ImageView realtimeToggleButton;
|
||||
boolean isRealtimeStatusRunning = false;
|
||||
ImageView backInPreview;
|
||||
private ImageView albumSelectButton;
|
||||
private View mCameraPageView;
|
||||
private ViewGroup mResultPageView;
|
||||
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 BTN_SHUTTER = 0;
|
||||
public static final int ALBUM_SELECT = 1;
|
||||
private static int TYPE = BTN_SHUTTER;
|
||||
|
||||
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
|
||||
PicoDet predictor = new PicoDet();
|
||||
|
||||
@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.detection_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();
|
||||
mCameraPageView.setVisibility(View.GONE);
|
||||
mResultPageView.setVisibility(View.VISIBLE);
|
||||
seekbarText.setText(resultNum + "");
|
||||
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
||||
resultImage.setImageBitmap(shutterBitmap);
|
||||
break;
|
||||
case R.id.btn_settings:
|
||||
startActivity(new Intent(DetectionMainActivity.this, DetectionSettingsActivity.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;
|
||||
// 判断是否已经赋予权限
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
// 如果应用之前请求过此权限但用户拒绝了请求,此方法将返回 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:
|
||||
mResultPageView.setVisibility(View.GONE);
|
||||
mCameraPageView.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) {
|
||||
mCameraPageView.setVisibility(View.GONE);
|
||||
mResultPageView.setVisibility(View.VISIBLE);
|
||||
seekbarText.setText(resultNum + "");
|
||||
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
||||
Uri uri = data.getData();
|
||||
String path = getRealPathFromURI(uri);
|
||||
picBitmap = decodeBitmap(path, 720, 1280);
|
||||
originPicBitmap = picBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
||||
resultImage.setImageBitmap(picBitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
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.png";
|
||||
}
|
||||
shutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888,true);
|
||||
originShutterBitmap = ARGB8888ImageBitmap.copy(Bitmap.Config.ARGB_8888,true);
|
||||
boolean modified = false;
|
||||
DetectionResult result = predictor.predict(
|
||||
ARGB8888ImageBitmap, savedImagePath, DetectionSettingsActivity.scoreThreshold);
|
||||
modified = result.initialized();
|
||||
if (!savedImagePath.isEmpty()) {
|
||||
synchronized (this) {
|
||||
DetectionMainActivity.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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
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() {
|
||||
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);
|
||||
mCameraPageView = findViewById(R.id.camera_page);
|
||||
mResultPageView = 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 DetectResultAdapter adapter = new DetectResultAdapter(this, R.layout.detection_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();
|
||||
DetectionSettingsActivity.resetSettings();
|
||||
}
|
||||
|
||||
public void checkAndUpdateSettings() {
|
||||
if (DetectionSettingsActivity.checkAndUpdateSettings(this)) {
|
||||
String realModelDir = getCacheDir() + "/" + DetectionSettingsActivity.modelDir;
|
||||
Utils.copyDirectoryFromAssets(this, DetectionSettingsActivity.modelDir, realModelDir);
|
||||
String realLabelPath = getCacheDir() + "/" + DetectionSettingsActivity.labelPath;
|
||||
Utils.copyFileFromAssets(this, DetectionSettingsActivity.labelPath, realLabelPath);
|
||||
|
||||
String modelFile = realModelDir + "/" + "model.pdmodel";
|
||||
String paramsFile = realModelDir + "/" + "model.pdiparams";
|
||||
String configFile = realModelDir + "/" + "infer_cfg.yml";
|
||||
String labelFile = realLabelPath;
|
||||
RuntimeOption option = new RuntimeOption();
|
||||
option.setCpuThreadNum(DetectionSettingsActivity.cpuThreadNum);
|
||||
option.setLitePowerMode(DetectionSettingsActivity.cpuPowerMode);
|
||||
option.enableRecordTimeOfRuntime();
|
||||
if (Boolean.parseBoolean(DetectionSettingsActivity.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(DetectionMainActivity.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) {
|
||||
DetectionMainActivity.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;
|
||||
}
|
||||
}
|
@@ -10,15 +10,15 @@ 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.AppCompatPreferenceActivity;
|
||||
import com.baidu.paddle.fastdeploy.app.ui.view.AppCompatPreferenceActivity;
|
||||
import com.baidu.paddle.fastdeploy.app.ui.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SettingsActivity extends AppCompatPreferenceActivity implements
|
||||
public class DetectionSettingsActivity extends AppCompatPreferenceActivity implements
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private static final String TAG = SettingsActivity.class.getSimpleName();
|
||||
private static final String TAG = DetectionSettingsActivity.class.getSimpleName();
|
||||
|
||||
static public int selectedModelIdx = -1;
|
||||
static public String modelDir = "";
|
||||
@@ -46,7 +46,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity implements
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// addPreferencesFromResource(R.xml.settings);
|
||||
addPreferencesFromResource(R.xml.detection_settings);
|
||||
ActionBar supportActionBar = getSupportActionBar();
|
||||
if (supportActionBar != null) {
|
@@ -1,255 +0,0 @@
|
||||
package com.baidu.paddle.fastdeploy.app.examples.detection;
|
||||
|
||||
|
||||
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.os.Bundle;
|
||||
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.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.baidu.paddle.fastdeploy.RuntimeOption;
|
||||
import com.baidu.paddle.fastdeploy.app.examples.R;
|
||||
import com.baidu.paddle.fastdeploy.app.ui.CameraSurfaceView;
|
||||
import com.baidu.paddle.fastdeploy.app.ui.Utils;
|
||||
import com.baidu.paddle.fastdeploy.vision.DetectionResult;
|
||||
import com.baidu.paddle.fastdeploy.vision.detection.PicoDet;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class MainActivity extends Activity implements View.OnClickListener, CameraSurfaceView.OnTextureChangedListener {
|
||||
private static final String TAG = MainActivity.class.getSimpleName();
|
||||
|
||||
CameraSurfaceView svPreview;
|
||||
TextView tvStatus;
|
||||
ImageButton btnSwitch;
|
||||
ImageButton btnShutter;
|
||||
ImageButton btnSettings;
|
||||
ImageView realtimeToggleButton;
|
||||
boolean isRealtimeStatusRunning = false;
|
||||
ImageView backInPreview;
|
||||
|
||||
String savedImagePath = "result.jpg";
|
||||
int lastFrameIndex = 0;
|
||||
long lastFrameTime;
|
||||
|
||||
// Call 'init' and 'release' manually later
|
||||
PicoDet predictor = new PicoDet();
|
||||
|
||||
@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.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:
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
SimpleDateFormat date = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
|
||||
synchronized (this) {
|
||||
savedImagePath = Utils.getDCIMDirectory() + File.separator + date.format(new Date()).toString() + ".png";
|
||||
}
|
||||
Toast.makeText(MainActivity.this, "Save snapshot to " + savedImagePath, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case R.id.btn_settings:
|
||||
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
|
||||
break;
|
||||
case R.id.realtime_toggle_btn:
|
||||
toggleRealtimeStyle();
|
||||
break;
|
||||
case R.id.back_in_preview:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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 = MainActivity.this.savedImagePath;
|
||||
}
|
||||
boolean modified = false;
|
||||
DetectionResult result = predictor.predict(
|
||||
ARGB8888ImageBitmap, savedImagePath, SettingsActivity.scoreThreshold);
|
||||
modified = result.initialized();
|
||||
if (!savedImagePath.isEmpty()) {
|
||||
synchronized (this) {
|
||||
MainActivity.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() {
|
||||
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);
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
public void initSettings() {
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.clear();
|
||||
editor.commit();
|
||||
SettingsActivity.resetSettings();
|
||||
}
|
||||
|
||||
public void checkAndUpdateSettings() {
|
||||
if (SettingsActivity.checkAndUpdateSettings(this)) {
|
||||
String realModelDir = getCacheDir() + "/" + SettingsActivity.modelDir;
|
||||
Utils.copyDirectoryFromAssets(this, SettingsActivity.modelDir, realModelDir);
|
||||
String realLabelPath = getCacheDir() + "/" + SettingsActivity.labelPath;
|
||||
Utils.copyFileFromAssets(this, SettingsActivity.labelPath, realLabelPath);
|
||||
|
||||
String modelFile = realModelDir + "/" + "model.pdmodel";
|
||||
String paramsFile = realModelDir + "/" + "model.pdiparams";
|
||||
String configFile = realModelDir + "/" + "infer_cfg.yml";
|
||||
String labelFile = realLabelPath;
|
||||
RuntimeOption option = new RuntimeOption();
|
||||
option.setCpuThreadNum(SettingsActivity.cpuThreadNum);
|
||||
option.setLitePowerMode(SettingsActivity.cpuPowerMode);
|
||||
option.enableRecordTimeOfRuntime();
|
||||
if (Boolean.parseBoolean(SettingsActivity.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(MainActivity.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) {
|
||||
MainActivity.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;
|
||||
}
|
||||
}
|
@@ -25,8 +25,8 @@ import android.widget.Toast;
|
||||
|
||||
import com.baidu.paddle.fastdeploy.RuntimeOption;
|
||||
import com.baidu.paddle.fastdeploy.app.examples.R;
|
||||
import com.baidu.paddle.fastdeploy.app.ui.CameraSurfaceView;
|
||||
import com.baidu.paddle.fastdeploy.app.ui.Utils;
|
||||
import com.baidu.paddle.fastdeploy.app.ui.view.CameraSurfaceView;
|
||||
import com.baidu.paddle.fastdeploy.vision.OCRResult;
|
||||
import com.baidu.paddle.fastdeploy.pipeline.PPOCRv2;
|
||||
import com.baidu.paddle.fastdeploy.vision.ocr.Classifier;
|
||||
@@ -37,8 +37,8 @@ import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class MainActivity extends Activity implements View.OnClickListener, CameraSurfaceView.OnTextureChangedListener {
|
||||
private static final String TAG = MainActivity.class.getSimpleName();
|
||||
public class OcrMainActivity extends Activity implements View.OnClickListener, CameraSurfaceView.OnTextureChangedListener {
|
||||
private static final String TAG = OcrMainActivity.class.getSimpleName();
|
||||
|
||||
CameraSurfaceView svPreview;
|
||||
TextView tvStatus;
|
||||
@@ -64,7 +64,7 @@ public class MainActivity extends Activity implements View.OnClickListener, Came
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
setContentView(R.layout.ocr_activity_main);
|
||||
|
||||
// Clear all setting items to avoid app crashing due to the incorrect settings
|
||||
initSettings();
|
||||
@@ -91,10 +91,10 @@ public class MainActivity extends Activity implements View.OnClickListener, Came
|
||||
synchronized (this) {
|
||||
savedImagePath = Utils.getDCIMDirectory() + File.separator + date.format(new Date()).toString() + ".png";
|
||||
}
|
||||
Toast.makeText(MainActivity.this, "Save snapshot to " + savedImagePath, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(OcrMainActivity.this, "Save snapshot to " + savedImagePath, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case R.id.btn_settings:
|
||||
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
|
||||
startActivity(new Intent(OcrMainActivity.this, OcrSettingsActivity.class));
|
||||
break;
|
||||
case R.id.realtime_toggle_btn:
|
||||
toggleRealtimeStyle();
|
||||
@@ -128,14 +128,14 @@ public class MainActivity extends Activity implements View.OnClickListener, Came
|
||||
public boolean onTextureChanged(Bitmap ARGB8888ImageBitmap) {
|
||||
String savedImagePath = "";
|
||||
synchronized (this) {
|
||||
savedImagePath = MainActivity.this.savedImagePath;
|
||||
savedImagePath = OcrMainActivity.this.savedImagePath;
|
||||
}
|
||||
boolean modified = false;
|
||||
OCRResult result = predictor.predict(ARGB8888ImageBitmap, savedImagePath);
|
||||
modified = result.initialized();
|
||||
if (!savedImagePath.isEmpty()) {
|
||||
synchronized (this) {
|
||||
MainActivity.this.savedImagePath = "result.jpg";
|
||||
OcrMainActivity.this.savedImagePath = "result.jpg";
|
||||
}
|
||||
}
|
||||
lastFrameIndex++;
|
||||
@@ -201,12 +201,12 @@ public class MainActivity extends Activity implements View.OnClickListener, Came
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.clear();
|
||||
editor.commit();
|
||||
SettingsActivity.resetSettings();
|
||||
OcrSettingsActivity.resetSettings();
|
||||
}
|
||||
|
||||
public void checkAndUpdateSettings() {
|
||||
if (SettingsActivity.checkAndUpdateSettings(this)) {
|
||||
String realModelDir = getCacheDir() + "/" + SettingsActivity.modelDir;
|
||||
if (OcrSettingsActivity.checkAndUpdateSettings(this)) {
|
||||
String realModelDir = getCacheDir() + "/" + OcrSettingsActivity.modelDir;
|
||||
// String detModelName = "ch_PP-OCRv2_det_infer";
|
||||
String detModelName = "ch_PP-OCRv3_det_infer";
|
||||
// String detModelName = "ch_ppocr_mobile_v2.0_det_infer";
|
||||
@@ -217,14 +217,14 @@ public class MainActivity extends Activity implements View.OnClickListener, Came
|
||||
String realDetModelDir = realModelDir + "/" + detModelName;
|
||||
String realClsModelDir = realModelDir + "/" + clsModelName;
|
||||
String realRecModelDir = realModelDir + "/" + recModelName;
|
||||
String srcDetModelDir = SettingsActivity.modelDir + "/" + detModelName;
|
||||
String srcClsModelDir = SettingsActivity.modelDir + "/" + clsModelName;
|
||||
String srcRecModelDir = SettingsActivity.modelDir + "/" + recModelName;
|
||||
String srcDetModelDir = OcrSettingsActivity.modelDir + "/" + detModelName;
|
||||
String srcClsModelDir = OcrSettingsActivity.modelDir + "/" + clsModelName;
|
||||
String srcRecModelDir = OcrSettingsActivity.modelDir + "/" + recModelName;
|
||||
Utils.copyDirectoryFromAssets(this, srcDetModelDir, realDetModelDir);
|
||||
Utils.copyDirectoryFromAssets(this, srcClsModelDir, realClsModelDir);
|
||||
Utils.copyDirectoryFromAssets(this, srcRecModelDir, realRecModelDir);
|
||||
String realLabelPath = getCacheDir() + "/" + SettingsActivity.labelPath;
|
||||
Utils.copyFileFromAssets(this, SettingsActivity.labelPath, realLabelPath);
|
||||
String realLabelPath = getCacheDir() + "/" + OcrSettingsActivity.labelPath;
|
||||
Utils.copyFileFromAssets(this, OcrSettingsActivity.labelPath, realLabelPath);
|
||||
|
||||
String detModelFile = realDetModelDir + "/" + "inference.pdmodel";
|
||||
String detParamsFile = realDetModelDir + "/" + "inference.pdiparams";
|
||||
@@ -236,16 +236,16 @@ public class MainActivity extends Activity implements View.OnClickListener, Came
|
||||
RuntimeOption detOption = new RuntimeOption();
|
||||
RuntimeOption clsOption = new RuntimeOption();
|
||||
RuntimeOption recOption = new RuntimeOption();
|
||||
detOption.setCpuThreadNum(SettingsActivity.cpuThreadNum);
|
||||
clsOption.setCpuThreadNum(SettingsActivity.cpuThreadNum);
|
||||
recOption.setCpuThreadNum(SettingsActivity.cpuThreadNum);
|
||||
detOption.setLitePowerMode(SettingsActivity.cpuPowerMode);
|
||||
clsOption.setLitePowerMode(SettingsActivity.cpuPowerMode);
|
||||
recOption.setLitePowerMode(SettingsActivity.cpuPowerMode);
|
||||
detOption.setCpuThreadNum(OcrSettingsActivity.cpuThreadNum);
|
||||
clsOption.setCpuThreadNum(OcrSettingsActivity.cpuThreadNum);
|
||||
recOption.setCpuThreadNum(OcrSettingsActivity.cpuThreadNum);
|
||||
detOption.setLitePowerMode(OcrSettingsActivity.cpuPowerMode);
|
||||
clsOption.setLitePowerMode(OcrSettingsActivity.cpuPowerMode);
|
||||
recOption.setLitePowerMode(OcrSettingsActivity.cpuPowerMode);
|
||||
detOption.enableRecordTimeOfRuntime();
|
||||
clsOption.enableRecordTimeOfRuntime();
|
||||
recOption.enableRecordTimeOfRuntime();
|
||||
if (Boolean.parseBoolean(SettingsActivity.enableLiteFp16)) {
|
||||
if (Boolean.parseBoolean(OcrSettingsActivity.enableLiteFp16)) {
|
||||
detOption.enableLiteFp16();
|
||||
clsOption.enableLiteFp16();
|
||||
recOption.enableLiteFp16();
|
||||
@@ -263,7 +263,7 @@ public class MainActivity extends Activity implements View.OnClickListener, Came
|
||||
@NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if (grantResults[0] != PackageManager.PERMISSION_GRANTED || grantResults[1] != PackageManager.PERMISSION_GRANTED) {
|
||||
new AlertDialog.Builder(MainActivity.this)
|
||||
new AlertDialog.Builder(OcrMainActivity.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.")
|
||||
@@ -271,7 +271,7 @@ public class MainActivity extends Activity implements View.OnClickListener, Came
|
||||
.setPositiveButton("Exit", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
MainActivity.this.finish();
|
||||
OcrMainActivity.this.finish();
|
||||
}
|
||||
}).show();
|
||||
}
|
@@ -10,15 +10,15 @@ 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.AppCompatPreferenceActivity;
|
||||
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 SettingsActivity extends AppCompatPreferenceActivity implements
|
||||
public class OcrSettingsActivity extends AppCompatPreferenceActivity implements
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private static final String TAG = SettingsActivity.class.getSimpleName();
|
||||
private static final String TAG = OcrSettingsActivity.class.getSimpleName();
|
||||
|
||||
static public int selectedModelIdx = -1;
|
||||
static public String modelDir = "";
|
@@ -1,4 +1,4 @@
|
||||
package com.baidu.paddle.fastdeploy.app.ui;
|
||||
package com.baidu.paddle.fastdeploy.app.ui.layout;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
@@ -1,4 +1,4 @@
|
||||
package com.baidu.paddle.fastdeploy.app.ui;
|
||||
package com.baidu.paddle.fastdeploy.app.ui.view;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
@@ -1,4 +1,4 @@
|
||||
package com.baidu.paddle.fastdeploy.app.ui;
|
||||
package com.baidu.paddle.fastdeploy.app.ui.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
@@ -15,6 +15,8 @@ import android.opengl.Matrix;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
import com.baidu.paddle.fastdeploy.app.ui.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
@@ -0,0 +1,43 @@
|
||||
package com.baidu.paddle.fastdeploy.app.ui.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class ResultListView extends ListView {
|
||||
public ResultListView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ResultListView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ResultListView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
private Handler handler;
|
||||
|
||||
public void setHandler(Handler mHandler) {
|
||||
handler = mHandler;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
removeAllViewsInLayout();
|
||||
invalidate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
|
||||
MeasureSpec.AT_MOST);
|
||||
super.onMeasure(widthMeasureSpec, expandSpec);
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
package com.baidu.paddle.fastdeploy.app.ui.view.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.baidu.paddle.fastdeploy.app.examples.R;
|
||||
import com.baidu.paddle.fastdeploy.app.ui.view.model.BaseResultModel;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
public class DetectResultAdapter extends ArrayAdapter<BaseResultModel> {
|
||||
private int resourceId;
|
||||
|
||||
public DetectResultAdapter(@NonNull Context context, int resource) {
|
||||
super(context, resource);
|
||||
}
|
||||
|
||||
public DetectResultAdapter(@NonNull Context context, int resource, @NonNull List<BaseResultModel> objects) {
|
||||
super(context, resource, objects);
|
||||
resourceId = resource;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
BaseResultModel model = getItem(position);
|
||||
View view = LayoutInflater.from(getContext()).inflate(resourceId, null);
|
||||
TextView indexText = (TextView) view.findViewById(R.id.index);
|
||||
TextView nameText = (TextView) view.findViewById(R.id.name);
|
||||
TextView confidenceText = (TextView) view.findViewById(R.id.confidence);
|
||||
indexText.setText(String.valueOf(model.getIndex()));
|
||||
nameText.setText(String.valueOf(model.getName()));
|
||||
confidenceText.setText(formatFloatString(model.getConfidence()));
|
||||
return view;
|
||||
}
|
||||
|
||||
public static String formatFloatString(float number) {
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
return df.format(number);
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
package com.baidu.paddle.fastdeploy.app.ui.view.model;
|
||||
|
||||
public class BaseResultModel {
|
||||
private int index;
|
||||
private String name;
|
||||
private float confidence;
|
||||
|
||||
public BaseResultModel() {
|
||||
|
||||
}
|
||||
|
||||
public BaseResultModel(int index, String name, float confidence) {
|
||||
this.index = index;
|
||||
this.name = name;
|
||||
this.confidence = confidence;
|
||||
}
|
||||
|
||||
public float getConfidence() {
|
||||
return confidence;
|
||||
}
|
||||
|
||||
public void setConfidence(float confidence) {
|
||||
this.confidence = confidence;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
@@ -1,99 +0,0 @@
|
||||
<?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="com.baidu.paddle.fastdeploy.app.examples.ocr.MainActivity">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/colorWindow">
|
||||
|
||||
<com.baidu.paddle.fastdeploy.app.ui.CameraSurfaceView
|
||||
android:id="@+id/sv_preview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_centerInParent="true" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="@dimen/top_bar_height"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:background="@color/colorTopBar">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginLeft="@dimen/top_bar_left_right_margin"
|
||||
android:layout_marginBottom="@dimen/top_bar_left_right_margin"
|
||||
android:textColor="@color/colorText"
|
||||
android:gravity="center"
|
||||
android:textSize="@dimen/small_font_size" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentRight="true"
|
||||
android:background="@color/colorBottomBar"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="@dimen/bottom_bar_top_margin"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"></LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="@dimen/large_button_height"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btn_switch"
|
||||
android:layout_width="@dimen/small_button_width"
|
||||
android:layout_height="@dimen/small_button_height"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="@dimen/bottom_bar_left_right_margin"
|
||||
android:layout_marginBottom="@dimen/bottom_bar_left_right_margin"
|
||||
android:background="#00000000"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/btn_switch" />
|
||||
|
||||
<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:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/btn_shutter" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btn_settings"
|
||||
android:layout_width="@dimen/small_button_width"
|
||||
android:layout_height="@dimen/small_button_width"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="@dimen/bottom_bar_left_right_margin"
|
||||
android:background="@null"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/btn_settings" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="@dimen/bottom_bar_bottom_margin"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"></LinearLayout>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</android.support.constraint.ConstraintLayout>
|
@@ -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/detection_camera_page"
|
||||
android:id="@+id/camera_page"></include>
|
||||
|
||||
<include
|
||||
layout="@layout/detection_result_page"
|
||||
android:id="@+id/result_page"
|
||||
android:visibility="gone"></include>
|
||||
</FrameLayout>
|
@@ -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/ocr_camera_page"
|
||||
android:id="@+id/camera_page"></include>
|
||||
|
||||
<include
|
||||
layout="@layout/ocr_result_page"
|
||||
android:id="@+id/result_page"
|
||||
android:visibility="gone"></include>
|
||||
</FrameLayout>
|
@@ -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/detection_camera_page"
|
||||
android:id="@+id/camera_page"></include>
|
||||
|
||||
<include
|
||||
layout="@layout/detection_result_page"
|
||||
android:id="@+id/result_page"
|
||||
android:visibility="gone"></include>
|
||||
</FrameLayout>
|
@@ -5,15 +5,15 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:keepScreenOn="true"
|
||||
tools:context="com.baidu.paddle.fastdeploy.app.examples.ocr.MainActivity">
|
||||
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.ActionBarLayout
|
||||
android:id="@+id/action_bar"
|
||||
<com.baidu.paddle.fastdeploy.app.ui.layout.ActionBarLayout
|
||||
android:id="@+id/action_bar_main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/action_bar_take_photo"
|
||||
android:textAlignment="center"
|
||||
android:visibility="gone" />
|
||||
android:visibility="gone"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/action_realtime_btn"
|
||||
@@ -52,16 +52,15 @@
|
||||
android:text="@string/action_bar_realtime"
|
||||
android:textAlignment="center" />
|
||||
</LinearLayout>
|
||||
</com.baidu.paddle.fastdeploy.app.ui.layout.ActionBarLayout>
|
||||
|
||||
</com.baidu.paddle.fastdeploy.app.ui.ActionBarLayout>
|
||||
|
||||
<!-- 时实-->
|
||||
<com.baidu.paddle.fastdeploy.app.ui.CameraSurfaceView
|
||||
<!-- 实时-->
|
||||
<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"
|
||||
android:layout_below="@+id/action_bar_main"
|
||||
android:layout_centerInParent="true" />
|
||||
|
||||
<ImageView
|
||||
@@ -73,8 +72,7 @@
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginBottom="145dp"
|
||||
android:background="@drawable/album_btn"
|
||||
android:scaleType="fitXY"
|
||||
android:visibility="gone"/>
|
||||
android:scaleType="fitXY" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_status"
|
160
java/android/app/src/main/res/layout/detection_result_page.xml
Normal file
160
java/android/app/src/main/res/layout/detection_result_page.xml
Normal file
@@ -0,0 +1,160 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#FFFFFF"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.baidu.paddle.fastdeploy.app.ui.layout.ActionBarLayout
|
||||
android:id="@+id/action_bar_result"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back_in_result"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:cropToPadding="true"
|
||||
android:paddingLeft="40px"
|
||||
android:paddingTop="60px"
|
||||
android:paddingRight="60px"
|
||||
android:paddingBottom="40px"
|
||||
android:src="@drawable/back_btn" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/model_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="50px"
|
||||
android:textColor="@color/textColor"
|
||||
android:textSize="@dimen/action_btn_text_size" />
|
||||
</com.baidu.paddle.fastdeploy.app.ui.layout.ActionBarLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="700px">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/result_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/bk_result_image_padding" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="40px"
|
||||
android:layout_marginTop="26px"
|
||||
android:layout_marginBottom="20px"
|
||||
android:text="@string/result_label"
|
||||
android:textColor="@color/bk_black"
|
||||
android:textSize="56px"
|
||||
android:visibility="visible" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/result_seekbar_section"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="130px"
|
||||
android:layout_marginLeft="@dimen/result_list_padding_lr"
|
||||
android:layout_marginRight="@dimen/result_list_padding_lr"
|
||||
android:layout_marginBottom="@dimen/result_list_gap_width"
|
||||
android:background="@drawable/result_page_border_section_bk"
|
||||
android:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="2"
|
||||
android:paddingLeft="30px"
|
||||
android:text="@string/result_table_header_confidence"
|
||||
android:textColor="@color/table_result_tableheader_text_color"
|
||||
android:textSize="@dimen/result_list_view_text_size" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/confidence_seekbar"
|
||||
android:layout_width="220dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="6"
|
||||
android:focusable="false"
|
||||
android:maxHeight="8px"
|
||||
android:progressDrawable="@drawable/seekbar_progress_result"
|
||||
android:splitTrack="false"
|
||||
android:thumb="@drawable/seekbar_handle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/seekbar_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:paddingRight="30px"
|
||||
android:textSize="@dimen/result_list_view_text_size"
|
||||
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/result_list_padding_lr"
|
||||
android:layout_marginRight="@dimen/result_list_padding_lr"
|
||||
android:layout_marginBottom="@dimen/result_list_gap_width"
|
||||
android:background="@drawable/result_page_border_section_bk"
|
||||
android:visibility="visible">
|
||||
|
||||
<TextView
|
||||
style="@style/list_result_view_tablehead_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/result_table_header_index"
|
||||
android:textColor="@color/table_result_tableheader_text_color" />
|
||||
|
||||
<TextView
|
||||
style="@style/list_result_view_tablehead_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/result_table_header_name"
|
||||
android:textColor="@color/table_result_tableheader_text_color" />
|
||||
|
||||
<TextView
|
||||
style="@style/list_result_view_tablehead_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.4"
|
||||
android:gravity="right"
|
||||
android:text="@string/result_table_header_confidence"
|
||||
android:textColor="@color/table_result_tableheader_text_color" />
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="15px"
|
||||
android:paddingLeft="@dimen/result_list_padding_lr"
|
||||
android:paddingRight="@dimen/result_list_padding_lr">
|
||||
|
||||
<com.baidu.paddle.fastdeploy.app.ui.view.ResultListView
|
||||
android:id="@+id/result_list_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="700px"
|
||||
android:divider="#FFFFFF"
|
||||
android:dividerHeight="@dimen/result_list_gap_width"></com.baidu.paddle.fastdeploy.app.ui.view.ResultListView>
|
||||
</ScrollView>
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/result_page_border_section_bk">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/index"
|
||||
style="@style/list_result_view_item_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="0.2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
style="@style/list_result_view_item_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="0.6"
|
||||
android:maxWidth="300px" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/confidence"
|
||||
style="@style/list_result_view_item_style"
|
||||
android:layout_weight="0.2"
|
||||
android:layout_width="wrap_content" />
|
||||
</LinearLayout>
|
14
java/android/app/src/main/res/layout/ocr_activity_main.xml
Normal file
14
java/android/app/src/main/res/layout/ocr_activity_main.xml
Normal file
@@ -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/ocr_camera_page"
|
||||
android:id="@+id/camera_page"></include>
|
||||
|
||||
<include
|
||||
layout="@layout/ocr_result_page"
|
||||
android:id="@+id/result_page"
|
||||
android:visibility="gone"></include>
|
||||
</FrameLayout>
|
161
java/android/app/src/main/res/layout/ocr_camera_page.xml
Normal file
161
java/android/app/src/main/res/layout/ocr_camera_page.xml
Normal file
@@ -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=".ocr.OcrMainActivity">
|
||||
|
||||
<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="300px"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/action_bar_realtime"
|
||||
android:textAlignment="center" />
|
||||
</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>
|
160
java/android/app/src/main/res/layout/ocr_result_page.xml
Normal file
160
java/android/app/src/main/res/layout/ocr_result_page.xml
Normal file
@@ -0,0 +1,160 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#FFFFFF"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.baidu.paddle.fastdeploy.app.ui.layout.ActionBarLayout
|
||||
android:id="@+id/action_bar_result"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back_in_result"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:cropToPadding="true"
|
||||
android:paddingLeft="40px"
|
||||
android:paddingTop="60px"
|
||||
android:paddingRight="60px"
|
||||
android:paddingBottom="40px"
|
||||
android:src="@drawable/back_btn" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/model_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="50px"
|
||||
android:textColor="@color/textColor"
|
||||
android:textSize="@dimen/action_btn_text_size" />
|
||||
</com.baidu.paddle.fastdeploy.app.ui.layout.ActionBarLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="700px">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/result_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/bk_result_image_padding" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="40px"
|
||||
android:layout_marginTop="26px"
|
||||
android:layout_marginBottom="20px"
|
||||
android:text="@string/result_label"
|
||||
android:textColor="@color/bk_black"
|
||||
android:textSize="56px"
|
||||
android:visibility="visible" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/result_seekbar_section"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="130px"
|
||||
android:layout_marginLeft="@dimen/result_list_padding_lr"
|
||||
android:layout_marginRight="@dimen/result_list_padding_lr"
|
||||
android:layout_marginBottom="@dimen/result_list_gap_width"
|
||||
android:background="@drawable/result_page_border_section_bk"
|
||||
android:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="2"
|
||||
android:paddingLeft="30px"
|
||||
android:text="@string/result_table_header_confidence"
|
||||
android:textColor="@color/table_result_tableheader_text_color"
|
||||
android:textSize="@dimen/result_list_view_text_size" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/confidence_seekbar"
|
||||
android:layout_width="220dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="6"
|
||||
android:focusable="false"
|
||||
android:maxHeight="8px"
|
||||
android:progressDrawable="@drawable/seekbar_progress_result"
|
||||
android:splitTrack="false"
|
||||
android:thumb="@drawable/seekbar_handle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/seekbar_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:paddingRight="30px"
|
||||
android:textSize="@dimen/result_list_view_text_size"
|
||||
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/result_list_padding_lr"
|
||||
android:layout_marginRight="@dimen/result_list_padding_lr"
|
||||
android:layout_marginBottom="@dimen/result_list_gap_width"
|
||||
android:background="@drawable/result_page_border_section_bk"
|
||||
android:visibility="visible">
|
||||
|
||||
<TextView
|
||||
style="@style/list_result_view_tablehead_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/result_table_header_index"
|
||||
android:textColor="@color/table_result_tableheader_text_color" />
|
||||
|
||||
<TextView
|
||||
style="@style/list_result_view_tablehead_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/result_table_header_name"
|
||||
android:textColor="@color/table_result_tableheader_text_color" />
|
||||
|
||||
<TextView
|
||||
style="@style/list_result_view_tablehead_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.4"
|
||||
android:gravity="right"
|
||||
android:text="@string/result_table_header_confidence"
|
||||
android:textColor="@color/table_result_tableheader_text_color" />
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="15px"
|
||||
android:paddingLeft="@dimen/result_list_padding_lr"
|
||||
android:paddingRight="@dimen/result_list_padding_lr">
|
||||
|
||||
<com.baidu.paddle.fastdeploy.app.ui.view.ResultListView
|
||||
android:id="@+id/result_list_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="700px"
|
||||
android:divider="#FFFFFF"
|
||||
android:dividerHeight="@dimen/result_list_gap_width"></com.baidu.paddle.fastdeploy.app.ui.view.ResultListView>
|
||||
</ScrollView>
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/result_page_border_section_bk">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/index"
|
||||
style="@style/list_result_view_item_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="0.2" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
style="@style/list_result_view_item_style"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="0.6"
|
||||
android:maxWidth="300px" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/confidence"
|
||||
style="@style/list_result_view_item_style"
|
||||
android:layout_weight="0.2"
|
||||
android:layout_width="wrap_content" />
|
||||
</LinearLayout>
|
@@ -1,9 +1,9 @@
|
||||
<resources>
|
||||
<!-- Default App name -->
|
||||
<string name="app_name">FastDeploy PicoDet</string>
|
||||
<string name="app_name">EasyEdge</string>
|
||||
<!-- Other App name -->
|
||||
<string name="detection_app_name">FastDeploy PicoDet</string>
|
||||
<string name="ocr_app_name">FastDeploy PP-OCRv2</string>
|
||||
<string name="detection_app_name">EasyEdge</string>
|
||||
<string name="ocr_app_name">EasyEdge</string>
|
||||
<!-- Keys for PreferenceScreen -->
|
||||
<string name="CHOOSE_PRE_INSTALLED_MODEL_KEY">CHOOSE_INSTALLED_MODEL_KEY</string>
|
||||
<string name="MODEL_DIR_KEY">MODEL_DIR_KEY</string>
|
||||
@@ -17,6 +17,7 @@
|
||||
<string name="CPU_POWER_MODE_DEFAULT">LITE_POWER_HIGH</string>
|
||||
<string name="SCORE_THRESHOLD_DEFAULT">0.4</string>
|
||||
<string name="ENABLE_LITE_FP16_MODE_DEFAULT">true</string>
|
||||
<!--Other values-->
|
||||
<!-- Default model & Label paths & other values ... -->
|
||||
<string name="MODEL_DIR_DEFAULT">models/picodet_s_320_coco_lcnet</string>
|
||||
<string name="LABEL_PATH_DEFAULT">labels/coco_label_list.txt</string>
|
||||
@@ -35,4 +36,4 @@
|
||||
<string name="operation_confidence_control">阈值控制</string>
|
||||
<string name="operation_retry">重新识别</string>
|
||||
<string name="operation_save">保存结果</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
17
java/android/app/src/main/res/values/values.xml
Normal file
17
java/android/app/src/main/res/values/values.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="action_btn_size">120dp</dimen>
|
||||
<dimen name="action_btn_text_size">46px</dimen>
|
||||
|
||||
<dimen name="operation_btn_margin_top_take_picture">126px</dimen>
|
||||
<dimen name="operation_btn_margin_top">136px</dimen>
|
||||
|
||||
<dimen name="result_list_view_text_size">46px</dimen>
|
||||
|
||||
<dimen name="result_list_popview_text_size">36px</dimen>
|
||||
|
||||
<dimen name="result_list_padding_lr">15dp</dimen>
|
||||
|
||||
<dimen name="result_list_gap_width">15dp</dimen>
|
||||
|
||||
</resources>
|
Reference in New Issue
Block a user