What is the best camera parameters for android camera opened in surface view
11,704
It has to do with the different preview sizes there are for the different phones.
The following method I used in a camera preview related android project:
Inside the surfaceCreated Method:
Camera camera = Camera.open(CameraInfo.CAMERA_FACING_BACK);
final Camera.Parameters params = camera.getParameters();
final Size size = getOptimalSize();
params.setPreviewSize(size.width, size.height);
camera.setParameters(params);
Inside the same activity:
private Size getOptimalSize() {
Camera.Size result = null;
final Camera.Parameters parameters = camera.getParameters();
Log.i(Preview.class.getSimpleName(), "window width: " + getWidth() + ", height: " + getHeight());
for (final Camera.Size size : parameters.getSupportedPreviewSizes()) {
if (size.width <= getWidth() * PREVIEW_SIZE_FACTOR && size.height <= getHeight() * PREVIEW_SIZE_FACTOR) {
if (result == null) {
result = size;
} else {
final int resultArea = result.width * result.height;
final int newArea = size.width * size.height;
if (newArea > resultArea) {
result = size;
}
}
}
}
if (result == null) {
result = parameters.getSupportedPreviewSizes().get(0);
}
Log.i(Preview.class.getSimpleName(), "Using PreviewSize: " + result.width + " x " + result.height);
return result;
}
Of course I should add, that the factor we used was: PREVIEW_SIZE_FACTOR = 1.30;
Author by
Harshjags
Updated on November 24, 2022Comments
-
Harshjags over 1 year
The below is my Android camera parameter printed using flaten(). I use Surface view and open my camera manually by using camera.open(). I set camera.paramter using setParameter().
-max=30;zoom=0;taking-picture-zoom=0;zoom-supported=true;sharpness-min=0;sharpness=10;contrast=5;whitebalance=auto;jpeg-quality=100;preview-format-values=yuv420sp;jpeg-thumbnail-quality=75;preview-format=yuv420sp;preview-size=576x432;focal-length=4.92;iso=auto;meter-mode=meter-center;front-camera-mode=mirror;flash-mode-values=off,auto,on,torch;preview-frame-rate-values=15;preview-frame-rate=15;focus-mode-values=auto,infinity;jpeg-thumbnail-width=768;jpeg-thumbnail-size-values=768x576,640x480,512x384,0x0;zoom-ratios=100,114,131,151,174,200;saturation-def=5;preview-size-values=1280x720,800x480,768x432,720x480,640x480,576x432,480x320,400x240,384x288,352x288,320x240,272x272,240x240,240x160,176x144;smart-contrast=off;picture-size-values=3264x2448,3264x1952,2592x1952,2592x1552,2048x1536,2048x1216,1600x1200,1280x960,1280x768,1024x768,640x480,640x384,512x384,400x400,272x272;contrast-min=0;min-exposure-compensation=-4;brightness-min=0;antibanding=auto;taking-picture-zoom-min=0;saturation-min=1;contrast-max=10;vertical-view-angle=38;taking-picture-zoom-max=30;contrast-def=5;brightness-max=6;horizontal-view-angle=49.5;brightness=3;jpeg-thumbnail-height=576;cam-mode=0;focus-mode=auto;sharpness-def=10;front-camera-mode-values=mirror,reverse;picture-format-values=jpeg;saturation-max=10;max-exposure-compensation=4;exposure-compensation=0;exposure-compensation-step=0.5;flash-mode=off;effect-values=none,mono,negative,solarize,sepia,posterize,aqua;meter-mode-values=meter-average,meter-center,meter-spot;picture-size=1024x768;max-zoom=5;effect=none;saturation=5;whitebalance-values=auto,incandescent,fluorescent,daylight,cloudy-daylight;picture-format=jpeg;brightness-def=3;iso-values=auto,deblur,100,200,400,800,1250;antibanding-values=off,50hz,60hz,auto**
**
- My camera images is not consistently same in all device. Certain Droid and old phones have image blur and image shrinking issues. Is there any specific parameter which need a fine tuning??
**
-
Harshjags over 10 yearsI had the exact method and implementation but still my users complaint of varied camera behaviour.
-
Mirco Widmer over 10 yearsI suppose there is no other way than to handle these specific devices/resolutions manually. I suggest setting the preview size to 1280x720 for this specific device.
-
Harshjags over 10 yearsI dint have the PREVIEW_SIZE_FACTOR = 1.30; in my code let me try implemnting that. But why are you increasing the width and height by 1.3?
-
Mirco Widmer over 10 yearsI'm not increasing the width and height, I'm just allowing a little distortion in the preview before switching to a lower resolution preview. In my experience a slightly distorted preview is better than having a lower preview resolution.
-
Harshjags over 10 yearsThanks for the immediate response. I will try this configuration. If I understand correctly we need not set up any specific parameter of camera. we just modify the supported preview size paramter of camera.
-
Mirco Widmer over 10 yearsThat's correct. IMO this is the only paramater which causes the distortion of the preview size.
-
Harshjags over 10 yearsI am testing these in couple of device will udpate you by tommorow
-
rupinderjeet over 7 yearsWill you by tomorrow?