简体   繁体   English

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

[英]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. 在Android的Camera2 API项目中,我想为我的曝光计算设置一个区域。 Unfortunately it doesn't work. 不幸的是它不起作用。 On the other side the Focus region works without any problems. 另一方面,福克斯地区没有任何问题。

Device: Samsung S7 / Nexus 5 设备:三星S7 / Nexus 5

1.) Initial values for CONTROL_AF_MODE & CONTROL_AE_MODE 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.) Create the MeteringRectangle List 2.)创建MeteringRectangle列表

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) 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.) Tell the camera to start Exposure control 4.)告诉相机启动曝光控制

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... CONTROL_AE_STATE始终位于CONTROL_AE_STATE_SEARCHING中,但不使用已配置的区域...

After long testing & development I've found an answer. 经过长时间的测试和开发,我找到了答案。

  1. The coordinate system - Camera 1 API VS Camera 2 API 坐标系 - Camera 1 API VS Camera 2 API

RED = CAM1; RED = CAM1; GREEN = CAM2; GREEN = CAM2; As shown in the image below, the blue rect are the coordinates for a possible focus/exposure area for the Cam1. 如下图所示,蓝色矩形是Cam1可能的对焦/曝光区域的坐标。 By using the Cam2 API, there must be firstly queried the max of the height and the width. 通过使用Cam2 API,必须首先查询高度和宽度的最大值。 Please find more info here . 在这里找到更多信息。

在此输入图像描述

  1. Initial values for CONTROL_AF_MODE & CONTROL_AE_MODE: See in the question above. CONTROL_AF_MODE&CONTROL_AE_MODE的初始值:请参阅上面的问题。

  2. Set the CONTROL_AE_REGIONS: See in the question above. 设置CONTROL_AE_REGIONS:请参阅上面的问题。

  3. Set the CONTROL_AE_PRECAPTURE_TRIGGER. 设置CONTROL_AE_PRECAPTURE_TRIGGER。

// This is how to tell the camera to start AE control //这是告诉相机启动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. The ''captureCallbackListener'' gives feedback of the AE control (of course also for AF control) ''captureCallbackListener''提供AE控制的反馈(当然也用于AF控制)

So this configuration works for the most Android phones. 所以这个配置适用于大多数Android手机。 Unfortunately it doesn't work for the Samsung S6/7. 不幸的是,它不适用于三星S6 / 7。 For this reason I've tested their Camera SDK, which can be found here . 出于这个原因,我测试了他们的Camera SDK,可以在这里找到。

After deep investigations I've found the config field ''SCaptureRequest.METERING_MODE''. 经过深入调查后,我发现了配置字段''SCaptureRequest.METERING_MODE''。 By setting this to the value of ''SCaptureRequest.METERING_MODE_MANUAL'', the AE area works also the Samsung phones. 通过将其设置为''SCaptureRequest.METERING_MODE_MANUAL''的值,AE区域也适用于三星手机。

I'll add an example to github asap. 我将尽快向github添加一个示例。

Recently I had the same problem and finally found a solution that helped me. 最近我遇到了同样的问题,终于找到了一个帮助我的解决方案。

All I needed to do was to step 1 pixel from the edges of the active sensor rectangle. 我需要做的就是从活动传感器矩形的边缘开始步进1像素。 In your example instead of this rectangle: 在您的示例中,而不是此矩形:

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

I would use this: 我会用这个:

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

and it started working as magic on both Samsung and Nexus 5! 它开始在三星和Nexus 5上起到魔力的作用! (note that you should also step 1 pixel from right/bottom edges if you use maximum values there) (请注意,如果在那里使用最大值,还应该从右/下边缘开始1像素)

It seems that many vendors have poorly implemented this part of 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. 如果计量区域位于捕获结果元数据中返回的已使用的android.scaler.cropRegion之外,则摄像机设备将忽略裁剪区域外的部分,并仅将结果矩形输出为结果元数据中的计量区域。 If the region is entirely outside the crop region, it will be ignored and not reported in the result metadata. 如果该区域完全位于裁剪区域之外,则将忽略该区域,并且不会在结果元数据中报告该区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM