mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 00:33:03 +08:00
[Bug Fix] fix camera preview size setting problem (#638)
* [Bug Fix] fix android app detail page errors * [Android] fix realtime camera mode and shutter * [Bug Fix] fix AllocateSegmentationResultFromJava error * [Bug Fix] fix camera preview size setting problem * [Model] use uint8 buffer instead of fp32 in ppseg postprocess * [Model] revert changes in ppseg * [Model] revert postprocess changes in ppseg
This commit is contained in:
@@ -375,4 +375,4 @@ void PaddleSegModel::DisableNormalizeAndPermute() {
|
|||||||
|
|
||||||
} // namespace segmentation
|
} // namespace segmentation
|
||||||
} // namespace vision
|
} // namespace vision
|
||||||
} // namespace fastdeploy
|
} // namespace fastdeploy
|
@@ -15,14 +15,14 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
<activity android:name=".facedet.FaceDetMainActivity">
|
<activity android:name=".segmentation.SegmentationMainActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".facedet.FaceDetSettingsActivity"
|
android:name=".segmentation.SegmentationSettingsActivity"
|
||||||
android:label="Settings">
|
android:label="Settings">
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
@@ -320,8 +320,13 @@ public class FaceDetMainActivity extends Activity implements View.OnClickListene
|
|||||||
|
|
||||||
public void initView() {
|
public void initView() {
|
||||||
TYPE = REALTIME_DETECT;
|
TYPE = REALTIME_DETECT;
|
||||||
CameraSurfaceView.EXPECTED_PREVIEW_WIDTH = 720;
|
// (1) EXPECTED_PREVIEW_WIDTH should mean 'height' and EXPECTED_PREVIEW_HEIGHT
|
||||||
CameraSurfaceView.EXPECTED_PREVIEW_HEIGHT = 360;
|
// should mean 'width' if the camera display orientation is 90 | 270 degree
|
||||||
|
// (Hold the phone upright to record video)
|
||||||
|
// (2) Smaller resolution is more suitable for lite face detection
|
||||||
|
// on mobile phone. So, we set this preview size (480,480) here.
|
||||||
|
CameraSurfaceView.EXPECTED_PREVIEW_WIDTH = 480;
|
||||||
|
CameraSurfaceView.EXPECTED_PREVIEW_HEIGHT = 480;
|
||||||
svPreview = (CameraSurfaceView) findViewById(R.id.sv_preview);
|
svPreview = (CameraSurfaceView) findViewById(R.id.sv_preview);
|
||||||
svPreview.setOnTextureChangedListener(this);
|
svPreview.setOnTextureChangedListener(this);
|
||||||
svPreview.switchCamera(); // Front camera for HumanSeg
|
svPreview.switchCamera(); // Front camera for HumanSeg
|
||||||
|
@@ -310,8 +310,13 @@ public class SegmentationMainActivity extends Activity implements View.OnClickLi
|
|||||||
|
|
||||||
public void initView() {
|
public void initView() {
|
||||||
TYPE = REALTIME_DETECT;
|
TYPE = REALTIME_DETECT;
|
||||||
CameraSurfaceView.EXPECTED_PREVIEW_WIDTH = 720;
|
// (1) EXPECTED_PREVIEW_WIDTH should mean 'height' and EXPECTED_PREVIEW_HEIGHT
|
||||||
CameraSurfaceView.EXPECTED_PREVIEW_HEIGHT = 360;
|
// should mean 'width' if the camera display orientation is 90 | 270 degree
|
||||||
|
// (Hold the phone upright to record video)
|
||||||
|
// (2) Smaller resolution is more suitable for Lite Portrait HumanSeg.
|
||||||
|
// So, we set this preview size (480,480) here.
|
||||||
|
CameraSurfaceView.EXPECTED_PREVIEW_WIDTH = 480;
|
||||||
|
CameraSurfaceView.EXPECTED_PREVIEW_HEIGHT = 480;
|
||||||
svPreview = (CameraSurfaceView) findViewById(R.id.sv_preview);
|
svPreview = (CameraSurfaceView) findViewById(R.id.sv_preview);
|
||||||
svPreview.setOnTextureChangedListener(this);
|
svPreview.setOnTextureChangedListener(this);
|
||||||
svPreview.switchCamera(); // Front camera for HumanSeg
|
svPreview.switchCamera(); // Front camera for HumanSeg
|
||||||
|
@@ -126,7 +126,7 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) {
|
public static Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) {
|
||||||
final double ASPECT_TOLERANCE = 0.1;
|
final double ASPECT_TOLERANCE = 0.3;
|
||||||
double targetRatio = (double) w / h;
|
double targetRatio = (double) w / h;
|
||||||
if (sizes == null) return null;
|
if (sizes == null) return null;
|
||||||
|
|
||||||
|
@@ -30,8 +30,8 @@ public class CameraSurfaceView extends GLSurfaceView implements Renderer,
|
|||||||
SurfaceTexture.OnFrameAvailableListener {
|
SurfaceTexture.OnFrameAvailableListener {
|
||||||
private static final String TAG = CameraSurfaceView.class.getSimpleName();
|
private static final String TAG = CameraSurfaceView.class.getSimpleName();
|
||||||
|
|
||||||
public static int EXPECTED_PREVIEW_WIDTH = 1280;
|
public static int EXPECTED_PREVIEW_WIDTH = 1280; // 1920
|
||||||
public static int EXPECTED_PREVIEW_HEIGHT = 720;
|
public static int EXPECTED_PREVIEW_HEIGHT = 720; // 960
|
||||||
|
|
||||||
protected int numberOfCameras;
|
protected int numberOfCameras;
|
||||||
protected int selectedCameraId;
|
protected int selectedCameraId;
|
||||||
@@ -99,6 +99,16 @@ public class CameraSurfaceView extends GLSurfaceView implements Renderer,
|
|||||||
private int vcTex2Screen;
|
private int vcTex2Screen;
|
||||||
private int tcTex2Screen;
|
private int tcTex2Screen;
|
||||||
|
|
||||||
|
public void setBitmapReleaseMode(boolean mode) {
|
||||||
|
synchronized (this) {
|
||||||
|
bitmapReleaseMode = mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap getBitmap() {
|
||||||
|
return ARGB8888ImageBitmap; // may null or recycled.
|
||||||
|
}
|
||||||
|
|
||||||
public interface OnTextureChangedListener {
|
public interface OnTextureChangedListener {
|
||||||
boolean onTextureChanged(Bitmap ARGB8888ImageBitmap);
|
boolean onTextureChanged(Bitmap ARGB8888ImageBitmap);
|
||||||
}
|
}
|
||||||
@@ -236,16 +246,6 @@ public class CameraSurfaceView extends GLSurfaceView implements Renderer,
|
|||||||
GLES20.glFlush();
|
GLES20.glFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBitmapReleaseMode(boolean mode) {
|
|
||||||
synchronized (this) {
|
|
||||||
bitmapReleaseMode = mode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Bitmap getBitmap() {
|
|
||||||
return ARGB8888ImageBitmap; // may null or recycled.
|
|
||||||
}
|
|
||||||
|
|
||||||
private float[] transformTextureCoordinates(float[] coords, float[] matrix) {
|
private float[] transformTextureCoordinates(float[] coords, float[] matrix) {
|
||||||
float[] result = new float[coords.length];
|
float[] result = new float[coords.length];
|
||||||
float[] vt = new float[4];
|
float[] vt = new float[4];
|
||||||
@@ -287,20 +287,28 @@ public class CameraSurfaceView extends GLSurfaceView implements Renderer,
|
|||||||
public void openCamera() {
|
public void openCamera() {
|
||||||
if (disableCamera) return;
|
if (disableCamera) return;
|
||||||
camera = Camera.open(selectedCameraId);
|
camera = Camera.open(selectedCameraId);
|
||||||
List<Size> supportedPreviewSizes = camera.getParameters().getSupportedPreviewSizes();
|
|
||||||
Size previewSize = Utils.getOptimalPreviewSize(supportedPreviewSizes, EXPECTED_PREVIEW_WIDTH,
|
|
||||||
EXPECTED_PREVIEW_HEIGHT);
|
|
||||||
Camera.Parameters parameters = camera.getParameters();
|
Camera.Parameters parameters = camera.getParameters();
|
||||||
parameters.setPreviewSize(previewSize.width, previewSize.height);
|
|
||||||
if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
|
|
||||||
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
|
|
||||||
}
|
|
||||||
camera.setParameters(parameters);
|
|
||||||
int degree = Utils.getCameraDisplayOrientation(context, selectedCameraId);
|
int degree = Utils.getCameraDisplayOrientation(context, selectedCameraId);
|
||||||
camera.setDisplayOrientation(degree);
|
camera.setDisplayOrientation(degree);
|
||||||
boolean rotate = degree == 90 || degree == 270;
|
boolean rotate = degree == 90 || degree == 270;
|
||||||
textureWidth = rotate ? previewSize.height : previewSize.width;
|
int adjusted_width = rotate ? EXPECTED_PREVIEW_HEIGHT : EXPECTED_PREVIEW_WIDTH;
|
||||||
textureHeight = rotate ? previewSize.width : previewSize.height;
|
int adjusted_height = rotate ? EXPECTED_PREVIEW_WIDTH : EXPECTED_PREVIEW_HEIGHT;
|
||||||
|
|
||||||
|
List<Size> supportedPreviewSizes = camera.getParameters().getSupportedPreviewSizes();
|
||||||
|
|
||||||
|
Size previewSize = Utils.getOptimalPreviewSize(
|
||||||
|
supportedPreviewSizes, adjusted_width, adjusted_height);
|
||||||
|
|
||||||
|
textureWidth = previewSize.width;
|
||||||
|
textureHeight = previewSize.height;
|
||||||
|
|
||||||
|
parameters.setPreviewSize(previewSize.width, previewSize.height);
|
||||||
|
camera.setParameters(parameters);
|
||||||
|
|
||||||
|
if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
|
||||||
|
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
|
||||||
|
}
|
||||||
|
|
||||||
// Destroy FBO and draw textures
|
// Destroy FBO and draw textures
|
||||||
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
|
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
|
||||||
GLES20.glDeleteFramebuffers(1, fbo, 0);
|
GLES20.glDeleteFramebuffers(1, fbo, 0);
|
||||||
|
Reference in New Issue
Block a user