Skip to content
Advertisement

Camera VIew OpenCV in Android Cannot FIt

I have a problem with cameraview opencv on android, on android device type samsung camera view doesn’t fit there is a black cut like picture 1 while on android device type xiaomi and realme it’s safe like picture 2. I took the middle resolution from supportPreviewSize and set the maxFrameSize to a ratio of 1:1, how can the camera view size be compatible with all current android devices? is this purely because my code is still wrong or is it the camera settings of the android device itself?

Picture 1 Device Samsung A51

Picture 2 Device Realme 3

setResolution() :

mCamera = android.hardware.Camera.open();Camera.Parameters params = mCamera.getParameters();
List<Camera.Size> listSizes = params.getSupportedPreviewSizes();
List<Camera.Size> listCapture = params.getSupportedPictureSizes();

int midResolution = listSizes.size() / 2;

cameraSize = listSizes.get(midResolution);

params.setPictureSize(cameraSize.width, cameraSize.height);
params.setVideoStabilization(true);
params.setPreviewSize(cameraSize.width, cameraSize.height);

mCamera.setParameters(params);
mCamera.startPreview();

setMaxFrameSize :

jCameraView.setResolution();
Camera.Size sizeMaxFrame = jCameraView.getSizeCamera();

jCameraView.setMaxFrameSize(sizeMaxFrame.height, sizeMaxFrame.height);

I set the maxFrameSize value to the same value using the height value from the setResolution() method

Sorry if my language or question is not easy to understand

Advertisement

Answer

This is because of the Camera2 framework which you are using . It is really a pain to work with that frameWork and provide support to all devices. To cope up with this issue the Android Team came up with new library for the same , which is CameraX . The documentation for the same are here :

https://developer.android.com/training/camerax

It provides rich support to most of the devices. And has lot of extra features which are known as Vendor Extensions , you will find more on it at the above link . This framework is built on top of Camera / Camera2 framework . So you should consider migrating to CameraX for better support to more devices , using the same code . Or you need to cater individual set of devices using the current framework .

Advertisement