由于this尚无明确答案,并且stackoverflow还没有关于Camera 2 API Gamma的问题/答案,因此我要求提供使用Android Camera 2 API修改Brightness,Contrast和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中发现的所有内容(包括演示.apk).
解决方法:
我的错误是在修改亮度(B),伽玛(G)或对比度(C)之前将Auto White Balance Mode(AWB)更改为CONTROL_AWB_MODE_OFF.
不要为自动白平衡设定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设置了自定义亮度,对比度,伽玛全部内容,希望文章能够帮你解决Android Camera2 API设置了自定义亮度,对比度,伽玛所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)