Android Camera2 increase brightness

我与影子孤独终老i 提交于 2019-11-30 07:55:11

问题


I am using android camera2 in my application to take continuous images, Here when I use camera2 getting image preview brightness very dark compare to original camera. I seen this but there is no similar requirement in that answer.

I tried to set brightness in camera2 as suggested here:

Note that this control will only be effective if android.control.aeMode != OFF. This control will take effect even when android.control.aeLock == true.

captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
            captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
            captureRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, true);
            captureRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, 6);

But it still showing preview as dark image only as shown below.

See the difference here:

Original Camera:

Using Camera2:

And what is the value I need to pass as second parameter in:

captureRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, 6);

I kept 6 because as suggested in doc's:

For example, if the exposure value (EV) step is 0.333, '6' will mean an exposure compensation of +2 EV; -3 will mean an exposure compensation of -1 EV.

But still no effect in brightness..


回答1:


Here it is:

Add below code in onConfigured() and unlockFocus()

captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,getRange());

By using the above code you will get the better preview. But your captured picture will remain as it is. To get the better picture as well use the same below code in captureStillPicture()

captureBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, getRange());

getRange is:

    private Range<Integer> getRange() {
    CameraCharacteristics chars = null;
    try {
        chars = mCameraManager.getCameraCharacteristics(mCameraId);
        Range<Integer>[] ranges = chars.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
        Range<Integer> result = null;
        for (Range<Integer> range : ranges) {
            int upper = range.getUpper();
            // 10 - min range upper for my needs
            if (upper >= 10) {
                if (result == null || upper < result.getUpper().intValue()) {
                    result = range;
                }
            }
        }
        if (result == null) {
            result = ranges[0];
        }
        return result;
    } catch (CameraAccessException e) {
        e.printStackTrace();
        return null;
    }
}



回答2:


CONTROL_AE_LOCK should be off. You have misinterpreted the doc, possibly document itself is a bit confusing.

Note that this control will only be effective if android.control.aeMode != OFF. This control will take effect even when android.control.aeLock == true.

What it means is that when AE lock is ON, the exposure compensation will be applied on the locked exposure and not on the instantaneous exposure at the time of taking picture.

Even in your repeat request, exposure is locked so it doesn't help.

Remove AE lock and it should work.




回答3:


You can try this

public void setBrightness(int value) {
    int brightness = (int) (minCompensationRange + (maxCompensationRange - minCompensationRange) * (value / 100f));
    previewRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, brightness);
    applySettings();
 }

private void applySettings() {
    captureSession.setRepeatingRequest(previewRequestBuilder.build(), null, null);
}



回答4:


First, don't lock autoexposure - that's not needed when adjusting exposure compensation.

Second, did you call CameraCaptureSession.setRepeatingRequest with your new capture request?




回答5:


While setting CONTROL_AE_EXPOSURE_COMPENSATION the second parameter as defined by docs is relative to CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP

The adjustment is measured as a count of steps, with the step size defined by android.control.aeCompensationStep and the allowed range by android.control.aeCompensationRange."

The value of 6 in the example for +2EV is correct only when step is 0.333 which is just an example.

Following code will give you the exposure compensation value to be used for +2EV

CameraManager manager = (CameraManager)this.getSystemService(Context.CAMERA_SERVICE);
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
double exposureCompensationSteps = characteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP).doubleValue();
int exposureCompensation = (int)( 2.0 / exposureCompensationSteps );

I would also suggest you check if the value is within the range specified by CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE



来源:https://stackoverflow.com/questions/47196243/android-camera2-increase-brightness

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