Ask Your Question
0

keep the same aspect of preview with different resolutions

asked 2013-07-23 11:42:01 -0500

telopena gravatar image

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

edit retag flag offensive close merge delete

Comments

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.

telopena gravatar imagetelopena ( 2013-07-28 09:03:41 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-07-24 09:06:48 -0500

This answer on stackoverflow will provide you with the solution. You can use the android parameter onSizeChanged to actually react to the changing resolution.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-07-23 11:42:01 -0500

Seen: 255 times

Last updated: Jul 24 '13