gpt4 book ai didi

Android Camera2 API 设置自定义亮度、对比度、 Gamma

转载 作者:太空宇宙 更新时间:2023-11-03 12:46:36 36 4
gpt4 key购买 nike

自<强>this 没有明确的答案,stackoverflow 没有关于 Camera 2 API Gamma 的问题/答案,我要求使用 Android Camera 2 API 修改亮度、对比度和 Gamma 的解决方案.
我的代码得到 range step :

Rational controlAECompensationStep = characteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP);
if (controlAECompensationStep != null) {
compensationStep = controlAECompensationStep.doubleValue();
}

Range<Integer> controlAECompensationRange = characteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
if (controlAECompensationRange != null) {
minCompensationRange = controlAECompensationRange.getLower();
maxCompensationRange = controlAECompensationRange.getUpper();
}

我设置百分比亮度的方法:

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() {
try {
captureSession.setRepeatingRequest(previewRequestBuilder.build(), null, null);
} catch (Exception e) {
e.printStackTrace();
}
}

但是这种方法不能正常工作。图像变为green , 比如 here .


我描述了我在 documentation 中找到的所有内容.

最佳答案

我的错误在于更改 Auto White Balance Mode(AWB)CONTROL_AWB_MODE_OFF在修改亮度 (B)、 Gamma (G) 或对比度 (C) 之前。
不要为AWB设置OFF模式,使用AUTO或其他可能的模式。


以百分比形式获取当前 B

public int getBrightnessValue() {
int absBRange = maxCompensationRange - minCompensationRange;
int value = getValue(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION);
return 100 * (value - minCompensationRange) / absBRange;
}

以百分比设置 B

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

以百分比设置 C

//set def channels (used for contrast)
TonemapCurve tc = previewRequestBuilder.get(CaptureRequest.TONEMAP_CURVE);
if (tc != null) {
channels = new float[3][];
for (int chanel = TonemapCurve.CHANNEL_RED; chanel <= TonemapCurve.CHANNEL_BLUE; chanel++) {
float[] array = new float[tc.getPointCount(chanel) * 2];
tc.copyColorCurve(chanel, array, 0);
channels[chanel] = array;
}
}


public void setContrast(int value) {
final int minContrast = 0;
final int maxContrast = 1;

if (channels == null || value > 100 || value < 0) {
return;
}

float contrast = minContrast + (maxContrast - minContrast) * (value / 100f);

float[][] newValues = new float[3][];
for (int chanel = TonemapCurve.CHANNEL_RED; chanel <= TonemapCurve.CHANNEL_BLUE; chanel++) {
float[] array = new float [channels[chanel].length];
System.arraycopy(channels[chanel], 0, array, 0, array.length);
for (int i = 0; i < array.length; i++) {
array[i] *= contrast;
}
newValues[chanel] = array;
}
TonemapCurve tc = new TonemapCurve(newValues[TonemapCurve.CHANNEL_RED], newValues[TonemapCurve.CHANNEL_GREEN], newValues[TonemapCurve.CHANNEL_BLUE]);
previewRequestBuilder.set(CaptureRequest.TONEMAP_MODE, CaptureRequest.TONEMAP_MODE_CONTRAST_CURVE);
previewRequestBuilder.set(CaptureRequest.TONEMAP_CURVE, tc);
applySettings();
}

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

G 仍在进行中。


上面的代码示例可能不是 100% 正确,如果您有更好的解决方案或发现错误,请告诉我 ;)

关于Android Camera2 API 设置自定义亮度、对比度、 Gamma ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42806855/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com