22
votes

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
have you find any solution of the problemSumit Marwha
@SumitMarwha Nope yet, Did you? ;)Shailendra Madda
not till now. Camera2 legacy phone does not improve brightness automaticallySumit Marwha
hello, Have you found the solution?Ronak Thakkar
@RonakThakkar Nope not yet :(Shailendra Madda

6 Answers

12
votes

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;
    }
}
1
votes

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.

1
votes

While setting CONTROL_AE_EXPOSURE_COMPENSATION the second parameter as defined by docs is relative to CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP

The adjustment is measured as a count of steps, with the step size defined by android.control.aeCompensationStep and the allowed range by android.control.aeCompensationRange."

The value of 6 in the example for +2EV is correct only when step is 0.333 which is just an example.

Following code will give you the exposure compensation value to be used for +2EV

CameraManager manager = (CameraManager)this.getSystemService(Context.CAMERA_SERVICE);
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
double exposureCompensationSteps = characteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP).doubleValue();
int exposureCompensation = (int)( 2.0 / exposureCompensationSteps );

I would also suggest you check if the value is within the range specified by CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE

1
votes

You can try this

public void setBrightness(int value) {
    int brightness = (int) (minCompensationRange + (maxCompensationRange - minCompensationRange) * (value / 100f));
    previewRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, brightness);
    applySettings();
 }

private void applySettings() {
    captureSession.setRepeatingRequest(previewRequestBuilder.build(), null, null);
}
1
votes

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.

0
votes

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

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