22

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..

Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138

6 Answers6

12

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;
    }
}
Ronak Thakkar
  • 2,515
  • 6
  • 31
  • 45
1

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.

mesibo
  • 3,970
  • 6
  • 25
  • 43
1

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

Bhoju
  • 71
  • 4
1

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);
}
Jayesh
  • 131
  • 5
1

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

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

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

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47
  • First, As I mentioned as note in my question I need to lock it because in official doc says that.. **Note that this control will only be effective if android.control.aeMode != OFF. This control will take effect even when android.control.aeLock == true** Second, I am calling `cameraCaptureSessions.setRepeatingRequest(captureRequestBuilder.build(), null, mBackgroundHandler);` in `updatePreview()`. – Shailendra Madda Nov 10 '17 at 05:55
  • "even when" means that the control works whether aeLock is true or false (though if it's true, normal auto-exposure is not running which is probably not what you want). Please check what your selected target frame rate is. Exposure compensation cannot cause the camera to run slower than the minimum target frame rate. – Eddy Talvala Mar 07 '18 at 20:48