Search code examples
androidandroid-cameraandroid-camera2

Android Camera2 API - Set AE-regions not working


In my Camera2 API project for Android, I want to set a region for my Exposure Calculation. Unfortunately it doesn't work. On the other hand the Focus region works without any problems.

Device: Samsung S7 / Nexus 5

1.) Initial values for CONTROL_AF_MODE & CONTROL_AE_MODE

mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);

2.) Create the MeteringRectangle List

meteringFocusRectangleList = new MeteringRectangle[]{new MeteringRectangle(0,0,500,500,1000)};

3.) Check if it is supported by the device and set the CONTROL_AE_REGIONS (same for CONTROL_AF_REGIONS)

if (camera2SupportHandler.cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE) > 0) {
      camera2SupportHandler.mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS, meteringFocusRectangleList);
}

4.) Tell the camera to start Exposure control

camera2SupportHandler.mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_START);

The CONTROL_AE_STATE is always in CONTROL_AE_STATE_SEARCHING, but doesn't use the configured regions...


Solution

  • After long testing & development I've found an answer.

    1. The coordinate system - Camera 1 API VS Camera 2 API

    RED = CAM1; GREEN = CAM2; As shown in the image below, the blue rect are the coordinates for a possible focus/exposure area for the Cam1. By using the Cam2 API, there must be firstly queried the max of the height and the width. Please find more info here.

    enter image description here

    1. Initial values for CONTROL_AF_MODE & CONTROL_AE_MODE: See in the question above.

    2. Set the CONTROL_AE_REGIONS: See in the question above.

    3. Set the CONTROL_AE_PRECAPTURE_TRIGGER.

    // This is how to tell the camera to start AE control

                    CaptureRequest captureRequest = camera2SupportHandler.mPreviewRequestBuilder.build();
                  camera2SupportHandler.mCaptureSession.setRepeatingRequest(captureRequest, captureCallbackListener, camera2SupportHandler.mBackgroundHandler);
                    camera2SupportHandler.mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
                    camera2SupportHandler.mCaptureSession.capture(captureRequest, captureCallbackListener, camera2SupportHandler.mBackgroundHandler);
    
    1. The ''captureCallbackListener'' gives feedback of the AE control (of course also for AF control)

    So this configuration works for the most Android phones. Unfortunately it doesn't work for the Samsung S6/7. For this reason I've tested their Camera SDK, which can be found here.

    After deep investigations I've found the config field ''SCaptureRequest.METERING_MODE''. By setting this to the value of ''SCaptureRequest.METERING_MODE_MANUAL'', the AE area works also the Samsung phones.

    I'll add an example to github asap.