问题描述
在我的Android Camera2 API项目中,我想为我的曝光计算"设置一个区域.不幸的是,它不起作用.另一方面,焦点"区域可以正常工作.
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 side the Focus region works without any problems.
设备:三星S7/Nexus 5
Device: Samsung S7 / Nexus 5
1.)CONTROL_AF_MODE&的初始值; CONTROL_AE_MODE
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.)创建MeteringRectangle列表
2.) Create the MeteringRectangle List
meteringFocusRectangleList = new MeteringRectangle[]{new MeteringRectangle(0,0,500,500,1000)};
3.)检查设备是否支持它,并设置CONTROL_AE_REGIONS(与CONTROL_AF_REGIONS相同)
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.)告诉相机开始曝光控制
4.) Tell the camera to start Exposure control
camera2SupportHandler.mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_START);
CONTROL_AE_STATE始终处于CONTROL_AE_STATE_SEARCHING,但不使用配置的区域...
The CONTROL_AE_STATE is always in CONTROL_AE_STATE_SEARCHING, but doesn't use the configured regions...
推荐答案
经过长时间测试&开发我找到了答案.
After long testing & development I've found an answer.
- 坐标系-Camera 1 API VS Camera 2 API
红色= CAM1;绿色= CAM2;如下图所示,蓝色矩形是Cam1可能的对焦/曝光区域的坐标.通过使用Cam2 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.
-
CONTROL_AF_MODE&的初始值CONTROL_AE_MODE:请参见上面的问题.
Initial values for CONTROL_AF_MODE & CONTROL_AE_MODE: See in the question above.
设置CONTROL_AE_REGIONS:请参见上面的问题.
Set the CONTROL_AE_REGIONS: See in the question above.
设置CONTROL_AE_PRECAPTURE_TRIGGER.
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);
- "captureCallbackListener"给出了AE控制的反馈(当然也包括AF控制)
经过深入研究,我发现了配置字段"SCaptureRequest.METERING_MODE".通过将其设置为"SCaptureRequest.METERING_MODE_MANUAL"的值,AE区域也适用于三星手机.
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.
我将在 github 上尽快添加一个示例.
I'll add an example to github asap.
这篇关于Android Camera2 API-设置AE区域不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!