Resize the camera stream

asked Aug 12 '14

Dany B. gravatar image

updated Aug 12 '14

Hi,

I'm trying to resize the camera stream in my android app. The default size is 720x480, and i want to rescale at the minimum supported size which is 320x240. My solution keeps the old aspect ratio, and don't find a way to redefine the new ratio. Does anyone know a solution?

CameraBridgeViewBase cameraBridge = (CameraBridgeViewBase) ((Activity) context).getWindow()
.getDecorView().findViewById(R.id.image);

Camera c = Camera.open(_idCamera);
Parameters parameters = c.getParameters();
parameters.setPictureSize(_widthImage, _heightImage);
parameters.setPreviewSize(_widthImage, _heightImage);
c.setParameters(parameters);
c.release();
c = null;

cameraBridge.setCameraIndex(_idCamera);

cameraBridge.setMaxFrameSize(_widthImage, _heightImage);
cameraBridge.getHolder().setFixedSize(_widthImage, _heightImage);

cameraBridge.setVisibility(SurfaceView.VISIBLE);
cameraBridge.setCvCameraViewListener(this);
cameraBridge.enableView();

I use the bellow method to retrieve the matrice.

public Mat onCameraFrame(CvCameraViewFrame inputFrame)
{
    this._image = inputFrame.rgba().clone();
    return inputFrame.rgba();
}

Thanks,

Preview: (hide)

Comments

First you have to check if the minimum size that you mention is supported : You can do that :

 camera = Camera.open();
 parameters = camera.getParameters();
 List<Size>SupporetdSizes = parameters.getSupportedPreviewSizes();
itay gravatar imageitay (Oct 2 '14)edit