Search code examples
javaandroidandroid-camera2huawei-mobile-serviceshuawei-developers

camera2 API - set white balance but get green picture


I have an issue when getting the previous color temperature of the picture taken and seting on the next picture using camera2 API.

if ( nbOfPict > 0 ){
       builder.set( CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_OFF );
       builder.set( CaptureRequest.COLOR_CORRECTION_MODE, CameraMetadata.COLOR_CORRECTION_MODE_TRANSFORM_MATRIX );
       builder.set( CaptureRequest.COLOR_CORRECTION_TRANSFORM, characteristics.get( CameraCharacteristics.SENSOR_CALIBRATION_TRANSFORM1 ) );
       builder.set( CaptureRequest.COLOR_CORRECTION_GAINS, colorTemperature );
}

and on the capture result

if ( nb == 0 ) {
       colorTemperature = result.get(CaptureResult.COLOR_CORRECTION_GAINS);
}

but after the second picture taken, the result picture became green like this on Huawei only, I don't know why. This post also have green picture but doesn't explain why.


Solution

  • You should also use the value of COLOR_CORRECTION_TRANSFORM from CaptureResult like you do with COLOR_CORRECTION_GAINS instead of using SENSOR_CALIBRATION_TRANSFORM1; the latter is meant for processing RAW images, not for using as a valid COLOR_CORRECTION_TRANSFORM.

    You could also consider simply locking AWB until you're done capturing images.