mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-04 16:22:57 +08:00
[Android] Remove redundant code for segmentation app (#642)
Remove redundant code for segmentation. Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
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;
|
||||||
@@ -16,30 +19,24 @@ 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.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;
|
||||||
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 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.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 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.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -59,9 +56,6 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
private ViewGroup resultPageView;
|
private ViewGroup resultPageView;
|
||||||
private ImageView resultImage;
|
private ImageView resultImage;
|
||||||
private ImageView backInResult;
|
private ImageView backInResult;
|
||||||
private SeekBar confidenceSeekbar;
|
|
||||||
private TextView seekbarText;
|
|
||||||
private float resultNum = 1.0f;
|
|
||||||
private ResultListView resultView;
|
private ResultListView resultView;
|
||||||
private Bitmap shutterBitmap;
|
private Bitmap shutterBitmap;
|
||||||
private Bitmap picBitmap;
|
private Bitmap picBitmap;
|
||||||
@@ -178,8 +172,6 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
svPreview.onPause();
|
svPreview.onPause();
|
||||||
cameraPageView.setVisibility(View.GONE);
|
cameraPageView.setVisibility(View.GONE);
|
||||||
resultPageView.setVisibility(View.VISIBLE);
|
resultPageView.setVisibility(View.VISIBLE);
|
||||||
seekbarText.setText(resultNum + "");
|
|
||||||
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
|
||||||
if (shutterBitmap != null && !shutterBitmap.isRecycled()) {
|
if (shutterBitmap != null && !shutterBitmap.isRecycled()) {
|
||||||
detail(shutterBitmap);
|
detail(shutterBitmap);
|
||||||
} else {
|
} else {
|
||||||
@@ -215,8 +207,6 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
cameraPageView.setVisibility(View.GONE);
|
cameraPageView.setVisibility(View.GONE);
|
||||||
resultPageView.setVisibility(View.VISIBLE);
|
resultPageView.setVisibility(View.VISIBLE);
|
||||||
seekbarText.setText(resultNum + "");
|
|
||||||
confidenceSeekbar.setProgress((int) (resultNum * 100));
|
|
||||||
Uri uri = data.getData();
|
Uri uri = data.getData();
|
||||||
String path = getRealPathFromURI(this, uri);
|
String path = getRealPathFromURI(this, uri);
|
||||||
Bitmap bitmap = decodeBitmap(path, 720, 1280);
|
Bitmap bitmap = decodeBitmap(path, 720, 1280);
|
||||||
@@ -339,36 +329,12 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
resultImage = findViewById(R.id.result_image);
|
resultImage = findViewById(R.id.result_image);
|
||||||
backInResult = findViewById(R.id.back_in_result);
|
backInResult = findViewById(R.id.back_in_result);
|
||||||
backInResult.setOnClickListener(this);
|
backInResult.setOnClickListener(this);
|
||||||
confidenceSeekbar = findViewById(R.id.confidence_seekbar);
|
|
||||||
seekbarText = findViewById(R.id.seekbar_text);
|
|
||||||
resultView = findViewById(R.id.result_list_view);
|
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) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void detail(Bitmap bitmap) {
|
private void detail(Bitmap bitmap) {
|
||||||
predictor.predict(bitmap, true, 0.4f);
|
predictor.predict(bitmap, true, 0.4f);
|
||||||
resultImage.setImageBitmap(bitmap);
|
resultImage.setImageBitmap(bitmap);
|
||||||
resultNum = 1.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
@SuppressLint("ApplySharedPref")
|
||||||
|
@@ -67,7 +67,7 @@
|
|||||||
android:layout_marginRight="@dimen/result_list_padding_lr"
|
android:layout_marginRight="@dimen/result_list_padding_lr"
|
||||||
android:layout_marginBottom="@dimen/result_list_gap_width"
|
android:layout_marginBottom="@dimen/result_list_gap_width"
|
||||||
android:background="@drawable/result_page_border_section_bk"
|
android:background="@drawable/result_page_border_section_bk"
|
||||||
android:visibility="visible">
|
android:visibility="gone">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
Reference in New Issue
Block a user