如何设置Camera2'AWB的值?

时间:2018-11-28 10:57:51

标签: android android-camera2

我从SeekBar(1-100)得到了一个值,即色温范围和(2500K -7500K),我尝试将其值设置为Camera2的AWB ...即使更改了该值,但是我的预览一直是绿色的。

这是我的代码:

//-------
      mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_OFF);
      mPreviewRequestBuilder.set(CaptureRequest.COLOR_CORRECTION_MODE, CaptureRequest.COLOR_CORRECTION_MODE_TRANSFORM_MATRIX);
      RggbChannelVector rggbChannelVector = MyRGGB.colorTemperature(progress);
      //mPreviewRequestBuilder.set(CaptureRequest.COLOR_CORRECTION_GAINS, rggbChannelVector);

MyGGB.class

public static RggbChannelVector colorTemperature(int progress) {
float temperature = progress / 100;
float red;
float green;
float blue;
//Calculate red
if (temperature <= 66)
  red = 255;
else {
  red = temperature - 60;
  red = (float) (329.698727446 * (Math.pow((double) red, -0.1332047592)));
  if (red < 0)
    red = 0;
  if (red > 255)
    red = 255;
}


//Calculate green
if (temperature <= 66) {
  green = temperature;
  green = (float) (99.4708025861 * Math.log(green) - 161.1195681661);
  if (green < 0)
    green = 0;
  if (green > 255)
    green = 255;
} else {
  green = temperature - 60;
  green = (float) (288.1221695283 * (Math.pow((double) green, -0.0755148492)));
  if (green < 0)
    green = 0;
  if (green > 255)
    green = 255;
}

//calculate blue
if (temperature >= 66)
  blue = 255;
else if (temperature <= 19)
  blue = 0;
else {
  blue = temperature - 10;
  blue = (float) (138.5177312231 * Math.log(blue) - 305.0447927307);
  if (blue < 0)
    blue = 0;
  if (blue > 255)
    blue = 255;
}

Log.e("RGB", "red=" + red + ", green=" + green + ", blue=" + blue);
return new RggbChannelVector((red / 255) * 2, (green / 255), (green / 255), (blue / 255) * 2);

} 我已经阅读了问题Camera2 API Set Custom White Balance & Temperature Color 但是void MyRGGB.colorTemperature()总是返回red=255.0green=0.0blue=0.0, 我不知道该怎么解决...

0 个答案:

没有答案