Android Camera2 API - 设置 AE 区域不起作用

Android Camera2 API - Set AE-regions not working

在我 Android 的 Camera2 API 项目中,我想为我的曝光计算设置一个区域。不幸的是它不起作用。另一方面,焦点区域工作没有任何问题。

设备:三星 S7 / Nexus 5

1.) 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.) 创建 MeteringRectangle 列表

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

3.) 检查设备是否支持并设置CONTROL_AE_REGIONS(与CONTROL_AF_REGIONS相同)

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

4.) 告诉相机开始曝光控制

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

CONTROL_AE_STATE 始终在 CONTROL_AE_STATE_SEARCHING 中,但不使用配置的区域...

经过长时间的测试和开发,我找到了答案。

  1. 坐标系-Camera 1 API VS Camera 2 API

红色 = CAM1;绿色 = CAM2;如下图所示,蓝色矩形是 Cam1 可能 focus/exposure 区域的坐标。使用Cam2 API,首先要查询高度和宽度的最大值。请查找更多信息 here

  1. CONTROL_AF_MODE 和 CONTROL_AE_MODE 的初始值:参见上面的问题。

  2. 设置CONTROL_AE_REGIONS:见上题

  3. 设置CONTROL_AE_PRECAPTURE_TRIGGER.

// 这是告诉相机开始AE控制的方法

                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. ''captureCallbackListener''给出AE控制的反馈(当然也用于AF控制)

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.

经过深入调查,我找到了配置字段“'SCaptureRequest.METERING_MODE'”。通过将其设置为“'SCaptureRequest.METERING_MODE_MANUAL'”的值,AE 区域也适用于三星手机。

我会尽快向 github 添加示例。

最近我遇到了同样的问题,终于找到了对我有帮助的解决方案。

我需要做的就是从活动传感器矩形的边缘移动 1 个像素。在您的示例中,而不是这个矩形:

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

我会用这个:

meteringRectangleList = new MeteringRectangle[]{new MeteringRectangle(1,1,500,500,1000)};

它开始在三星和 Nexus 5 上发挥神奇的作用! (请注意,如果你在那里使用最大值,你还应该从 right/bottom 边缘步进 1 个像素)

好像很多厂商都没有很好的实现这部分documentation

If the metering region is outside the used android.scaler.cropRegion returned in capture result metadata, the camera device will ignore the sections outside the crop region and output only the intersection rectangle as the metering region in the result metadata. If the region is entirely outside the crop region, it will be ignored and not reported in the result metadata.