Android Camera2 increase brightness

Viewed 7605

I am using android camera2 in my application to take continuous images, Here when I use camera2 getting image preview brightness very dark compare to original camera. I seen this but there is no similar requirement in that answer.

I tried to set brightness in camera2 as suggested here:

Note that this control will only be effective if android.control.aeMode != OFF. This control will take effect even when android.control.aeLock == true.

captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
            captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
            captureRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, true);
            captureRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, 6);

But it still showing preview as dark image only as shown below.

See the difference here:

Original Camera: enter image description here

Using Camera2: enter image description here

And what is the value I need to pass as second parameter in:

captureRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, 6);

I kept 6 because as suggested in doc's:

For example, if the exposure value (EV) step is 0.333, '6' will mean an exposure compensation of +2 EV; -3 will mean an exposure compensation of -1 EV.

But still no effect in brightness..

6 Answers

Here it is:

Add below code in onConfigured() and unlockFocus()

captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,getRange());

By using the above code you will get the better preview. But your captured picture will remain as it is. To get the better picture as well use the same below code in captureStillPicture()

captureBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, getRange());

getRange is:

    private Range<Integer> getRange() {
    CameraCharacteristics chars = null;
    try {
        chars = mCameraManager.getCameraCharacteristics(mCameraId);
        Range<Integer>[] ranges = chars.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
        Range<Integer> result = null;
        for (Range<Integer> range : ranges) {
            int upper = range.getUpper();
            // 10 - min range upper for my needs
            if (upper >= 10) {
                if (result == null || upper < result.getUpper().intValue()) {
                    result = range;
                }
            }
        }
        if (result == null) {
            result = ranges[0];
        }
        return result;
    } catch (CameraAccessException e) {
        e.printStackTrace();
        return null;
    }
}

CONTROL_AE_LOCK should be off. You have misinterpreted the doc, possibly document itself is a bit confusing.

Note that this control will only be effective if android.control.aeMode != OFF. This control will take effect even when android.control.aeLock == true.

What it means is that when AE lock is ON, the exposure compensation will be applied on the locked exposure and not on the instantaneous exposure at the time of taking picture.

Even in your repeat request, exposure is locked so it doesn't help.

Remove AE lock and it should work.

I messed around with CaptureRequest.SENSOR_SENSITIVITY and it worked great on my Samsung s3, s7 and s8 phones.

You can get the CameraCharacteristics.SENSOR_INFO_SENSITIVITY_RANGE

sensitivity_range = chars.get(CameraCharacteristics.SENSOR_INFO_SENSITIVITY_RANGE);

On my s7, the range is from mid 50s to more than 3000. I then set it to 1500 as follows.

mCaptureRequest.set(CaptureRequest.SENSOR_SENSITIVITY, 1500);

It brightened the preview a few factors.

First, don't lock autoexposure - that's not needed when adjusting exposure compensation.

Second, did you call CameraCaptureSession.setRepeatingRequest with your new capture request?

Related