For this purpose, a digital gain correction can be applied per color channel (red, green, blue).
To automatically correct color shifts, use the Balance White Auto feature.
In this topic Hide
Images acquired by your camera may have a color cast, i.e., a tint of a particular color. The reason for this is that different sources of light have different color temperatures. Fluorescent lighting adds a bluish cast to images whereas tungsten incandescent light adds a yellowish cast.
The white balance feature allows you to correct these color shifts by adjusting the intensity of the colors red, green, and blue. As a result, white objects appear white in the acquired images.
// Set the red intensity to 108.789%
camera.BalanceRatioSelector.SetValue(BalanceRatioSelector_Red);
camera.BalanceRatioAbs.SetValue(1.08789);
// Set the green intensity to 100%
camera.BalanceRatioSelector.SetValue(BalanceRatioSelector_Green);
camera.BalanceRatioAbs.SetValue(1);
// Set the blue intensity to 219.678%
camera.BalanceRatioSelector.SetValue(BalanceRatioSelector_Blue);
camera.BalanceRatioAbs.SetValue(2.19678);
INodeMap& nodemap = camera.GetNodeMap();
// Set the red intensity to 108.789%
CEnumerationPtr(nodemap.GetNode("BalanceRatioSelector"))->FromString("Red");
CFloatPtr(nodemap.GetNode("BalanceRatioAbs"))->SetValue(1.08789);
// Set the green intensity to 100%
CEnumerationPtr(nodemap.GetNode("BalanceRatioSelector"))->FromString("Green");
CIntegerPtr(nodemap.GetNode("BalanceRatioAbs"))->SetValue(1);
// Set the blue intensity to 219.678%
CEnumerationPtr(nodemap.GetNode("BalanceRatioSelector"))->FromString("Blue");
CFloatPtr(nodemap.GetNode("BalanceRatioAbs"))->SetValue(2.19678);
// Set the red intensity to 108.789%
camera.Parameters[PLCamera.BalanceRatioSelector].SetValue(PLCamera.BalanceRatioSelector.Red);
camera.Parameters[PLCamera.BalanceRatioAbs].SetValue(1.08789);
// Set the green intensity to 100%
camera.Parameters[PLCamera.BalanceRatioSelector].SetValue(PLCamera.BalanceRatioSelector.Green);
camera.Parameters[PLCamera.BalanceRatioAbs].SetValue(1);
// Set the blue intensity to 219.678%
camera.Parameters[PLCamera.BalanceRatioSelector].SetValue(PLCamera.BalanceRatioSelector.Blue);
camera.Parameters[PLCamera.BalanceRatioAbs].SetValue(2.19678);
// Set the red intensity to 108.789%
Pylon.DeviceFeatureFromString(hdev, "BalanceRatioSelector", "Red");
Pylon.DeviceSetFloatFeature(hdev, "BalanceRatioAbs", 1.08789);
// Set the green intensity to 100%
Pylon.DeviceFeatureFromString(hdev, "BalanceRatioSelector", "Green");
Pylon.DeviceSetIntegerFeature(hdev, "BalanceRatioAbs", 1);
// Set the blue intensity to 219.678%
Pylon.DeviceFeatureFromString(hdev, "BalanceRatioSelector", "Blue");
Pylon.DeviceSetFloatFeature(hdev, "BalanceRatioAbs", 2.19678);
/* Macro to check for errors */
#define CHECK(errc) if (GENAPI_E_OK != errc) printErrorAndExit(errc)
GENAPIC_RESULT errRes = GENAPI_E_OK; /* Return value of pylon methods */
/* Set the red intensity to 108.789% */
errRes = PylonDeviceFeatureFromString(hdev, "BalanceRatioSelector", "Red");
CHECK(errRes);
errRes = PylonDeviceSetFloatFeature(hdev, "BalanceRatioAbs", 1.08789);
CHECK(errRes);
/* Set the green intensity to 100% */
errRes = PylonDeviceFeatureFromString(hdev, "BalanceRatioSelector", "Green");
CHECK(errRes);
errRes = PylonDeviceSetIntegerFeature(hdev, "BalanceRatioAbs", 1);
CHECK(errRes);
/* Set the blue intensity to 219.678% */
errRes = PylonDeviceFeatureFromString(hdev, "BalanceRatioSelector", "Blue");
CHECK(errRes);
errRes = PylonDeviceSetFloatFeature(hdev, "BalanceRatioAbs", 2.19678);
CHECK(errRes);
You can also use the pylon Viewer to easily set the parameters.