Android Camera2 API - Set AE-regions not working

孤街浪徒 提交于 2019-12-04 12:45:55

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.

  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.

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. 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! (note that you should also step 1 pixel from right/bottom edges if you use maximum values there)

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. If the region is entirely outside the crop region, it will be ignored and not reported in the result metadata.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!