keep the same aspect of preview with different resolutions
I am doing an Android application with opencv, and i want that when the user changes the resolution, the preview image keep the size. Any ideas?
this is my java class which controls camera:
package com.example.telo3;
import java.util.List;
import org.opencv.android.JavaCameraView;
import org.opencv.android.NativeCameraView;
import android.content.Context;
import android.hardware.Camera.Size;
import android.util.AttributeSet;
import android.util.Log;
public class ControlCamera extends JavaCameraView {
public ControlCamera(Context context, AttributeSet attrs) {
super(context, attrs);
mMaxWidth=176;
mMaxHeight=144;
}
@SuppressWarnings("static-access")
public int comprobar_camara() {
return (mCamera.getNumberOfCameras());
}
public List<Size> getResolutionList() {
return mCamera.getParameters().getSupportedPreviewSizes();
}
public void setResolution(Size resolution) {
disconnectCamera();
mMaxHeight = resolution.height;
mMaxWidth = resolution.width;
connectCamera(getWidth(), getHeight());
}
public Size getResolution() {
return mCamera.getParameters().getPreviewSize();
}
}
this my layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >
<com.example.telo3.ControlCamera
android:id="@+id/tutorial5_activity_java_surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
opencv:camera_id="front"
opencv:show_fps="true" />
<com.example.telo3.ControlCamera
android:id="@+id/tutorial5_activity_java_surface_view2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
opencv:camera_id="back"
opencv:show_fps="true" />
</RelativeLayout>
thanks
I solved my problem. I donwloaded the last version of Opencv and with this version I can see all the resolutions with the same aspect.