当前位置:网站首页>FLIR blackfly s industrial camera: auto exposure configuration and code

FLIR blackfly s industrial camera: auto exposure configuration and code

2022-07-07 02:00:00 The moon shines on the silver sea like a dragon

Auto exposure

Auto exposure optimizes the brightness of the image by adjusting the gain and exposure time .

Automatic exposure in the camera is reduced CPU Post processing operation .

What is the target gray value ( Exposure value )

The target gray value is a parameter , By adjusting the brightness , To realize the output of optimized image results under various light intensities
The value is linear , Is the percentage of the maximum pixel value .

In all kinds of digital cameras , The target gray value is called the exposure value , It depends on the aperture size 、f-stop And shutter time estimation .

How to distinguish whether the exposure value is correct

Image pixel intensity is usually used n Who said . Common are 8 position 、10 Bit or 16 Bit pixel format
Monochrome images have one channel per pixel , Color images usually have three channels per pixel (R、G、B).
Merge the image pixel values in the histogram to display the pixel intensity distribution of the image .
In this way, it can indicate when the image is underexposed 、 Correct exposure or overexposure

The following examples show One Underexposure , Overexposed and correctly exposed images , And the histogram of its pixels is given below .

To see whether the exposure of the image is reasonable, we usually use histogram
 Insert picture description here
 Insert picture description here
It's on it Underexposure Pictures and histograms of , It is obvious that most of the histograms are concentrated on the left , This means that the camera sensor does not capture enough light to correctly eliminate the dark areas

 Insert picture description here
 Insert picture description here
The picture above is Overexposure Of , The histogram is mostly concentrated on the left , signify , Some pixels are oversaturated , Pixel information is missing or clipped .

 Insert picture description here
 Insert picture description here
The picture above is The exposure is correct , You can see that the histogram is close to 128, In the middle , It means that the exposure value of the image is appropriate , The loss of data information is the least .

Auto exposure is a workflow

There are three image parameters that affect the exposure of the camera :

  • gain
  • time of exposure
  • iris ( It's not standard GenICam function )

The steps of automatic exposure are as follows :

  • 1 Expose the image with a default parameter value
  • 2 Create histograms and compare statistical data
    Compare image statistics using histograms .
    The histogram obtained is compared with the best mean and variance to determine the best exposure .
    If the average / The variance is not in the optimal range , Then the camera will adjust the gain or exposure .

Just like the picture below , Form a control loop
 Insert picture description here
You can automatically set the best image mean or define it using the target gray value , This value controls the position of the image histogram mean .
The target gray value is the percentage of the maximum value of the pixel format .

for example , Set the target gray value to 50% Of 8 Bit pixel format , Gain and exposure time pass through some linear functions ( for example gamma perhaps LUT) Automatic adjustment makes the average value of histogram in 128, To expose the image

When the target gray value is set automatically , The camera determines the optimal mean based on the variance of image pixels .
In this mode , gain 、 The upper and lower limits of exposure time and target gray value can be set .

When the target gray value is automatically set off , You can customize the mean . This average can be calculated by using the exposure value , Make compensation .

Exposure value is a method of manually adjusting the target gray value to adapt to special situations ( Such as sunshine or shadow ), The exposure value is determined by -3 To 3

  • 3 Adjust the gain and exposure time
    When the histogram does not match the best gray value, the two image parameters of gain and exposure time need to be adjusted

Gain converts sensor photons to output ( Electronics ) Convert to numeric value . The digital value is proportional to the gain setting , Therefore, the number of electrons required for unit bit change is proportional to the gain setting . White balance is on the sensor R、G and B Gain compensation of output difference . Automatic exposure takes into account the gain change of white balance .

time of exposure ( Shutter ) Determines the amount of time the sensor collects photons and converts them into electrons . It controls how much light the sensor collects .

In addition to these functions , Two additional functions can also be enabled through automatic exposure , Shock absorption and priority control , To provide supplementary control of the auto exposure algorithm .

How to set auto exposure

Flir Upper computer of industrial camera SpinView and Spinnaker API There are several ways to configure auto exposure .

use SpinView Configure auto exposure

Here is the passage SpinView To turn on the method of automatic exposure :

  • 1 open SpinView Apply and enter the setup menu
  • 2 Set up Exposure Auto by Continuous
  • 3 Set up Gain Auto by Continuous
     Insert picture description here
    Can be in SpinView Other optional auto exposure related functions set in are as follows , To enter the configuration interface, click Features Menu and select Auto Algorithm Control.
     Insert picture description here

adopt Spinnaker API To configure auto exposure

Here is the passage Spinnaker API To configure automatic exposure C++ routine

take Automatic Exposure Time and Gain Auto Set to automatic mode

// Set up  Exposure time mode  In automatic mode 
CEnumerationPtr ptrExposureAuto = nodeMap.GetNode("ExposureAuto");
CEnumEntryPtr ptrExposureAutoCts = ptrExposureAuto->GetEntryByName("Continuous");
ptrExposureAuto->SetIntValue(ptrExposureAutoCts->GetValue());

// Set up  gain  In automatic mode 
CEnumerationPtr ptrGainAuto = nodeMap.GetNode("GainAuto");
CEnumEntryPtr ptrGainAutoCts = ptrGainAuto->GetEntryByName("Continuous");
ptrGainAuto->SetIntValue(ptrGainAutoCts->GetValue());

Region of interest (ROI) It can be applied to the auto exposure function . This AE ROI Can be equal to or less than the captured ROI The area of .

// Auto exposure  ROI
// Turn on  ROI For white balance 
CBooleanPtrptrAasRoiEnable = nodeMap.GetNode("AasRoiEnable");
ptrAasRoiEnable-> SetValue(1);
CEnumerationPtr ptrAutoAlgorithmSelector = nodeMap.GetNode("AutoAlgorithmSelector");
CEnumEntryPtr ptrAutoAlgorithmSelectorAWB = ptrAutoAlgorithmSelector ->GetEntryByName("AutoWhiteBalance");
ptrAutoAlgorithmSelector->SetIntValue(ptrAutoAlgorithmSelectorAWB->GetValue());

// Set up ROI Size and offset of  
CIntptrptrAasRoiHeight = nodemap.GetNode("AasRoiHeight");
ptrAasRoiHeight->SetValue([insert ROI height]);
CIntptrptrAasRoWidth = nodemap.GetNode("AasRoiWidth");
ptrAasRoiWidth->SetValue([insert ROI width]);
CIntptrptrAasRoiOffsetX = nodemap.GetNode("AasRoiOffsetX");
ptrAasRoiOffsetX->SetValue([insert X offset]);
CIntptr ptrAasRoiOffsetY = nodemap.GetNode("AasRoiOffsetY");
ptrAasRoiOffsetY->SetValue([insert Y offset]);

The target gray value is set to automatic (continuous) The camera is allowed to determine the best average value according to the image variance .

// The target gray value is set to automatic 
CEnumerationPtr, ptrAutoXTargetGreyValueAuto = nodeMap.GetNode("AutoExposureTargetGreyValueAuto");
CEnumEntryPtr ptrAutoXTargetGreyValueAutoCts = ptrAutoXTargetGreyValueAuto ->GetEntryByName("Continuous");
ptrAutoXTargetGreyValueAuto -> ptrAutoXTargetGreyValueAutoCts ->GetValue());

When the illumination in the image is uneven , The illumination mode adjusts the exposure value to fit the features in the image histogram . The standard setting is normal . The other two options are backlight compensation and front light compensation :

Backlight compensation :
When a strong light comes in from behind an object , Use backlight compensation mode . under these circumstances , The automatic exposure algorithm will make the object underexposed . Implement backlight compensation and adjust imaging parameters to correctly expose images , Regardless of the position of the object relative to the camera and lighting position .

// Backlight compensation 
CEnumerationPtr ptrAutoXLightingMode = nodeMap.GetNode("AutoExposureLightingMode");
CEnumEntryPtr ptrAutoXLightingModeBacklight=ptrAutoXLightingMode->GetEntryByName("Backlight");
ptrAutoXLightingMode->SetIntValue(ptrAutoXLightingModeBacklight->GetValue());

Front light compensation :
When there is strong light in front of the object and the background is dark , Use the front light compensation mode . under these circumstances , The auto exposure algorithm will overexpose the object . The front light compensation adjusts the imaging parameters to correctly expose the image , Regardless of the position of the object relative to the camera and lighting .

// Front light compensation 
CEnumerationPtrptrAutoXLightingMode = nodeMap.GetNode("AutoExposureLightingMode");
CEnumEntrPtr ptrAutoXLightingModeFrontlight=ptrAutoXLightingMode->GetEntryByName("Frontlight");
ptrAutoXLightingMode->SetIntValue(ptrAutoXLightingModeFrontlight->GetValue());

Set various auto exposure parameter limits , Set the lower limit and upper limit of the target gray value .

// Target gray value range setting 
CFloatPtr ptrAutoXGreyValueLowerLimit = nodeMap.GetNode("AutoExposureGreyValueLowerLimit");
ptrAutoXGreyValueLowerLimit->SetValue([insert lower limit]);
CFloatPtr ptrAutoXGreyValueUpperLimit = nodeMap.GetNode("AutoExposureGreyValueUpperLimit");
ptrAutoXGreyValueUpperLimit->SetValue([insert upper limit]);

// Gain range setting 
CFloatPtr ptrAutoXGainLowerLimit = nodeMap.GetNode("AutoExposureGainLowerLimit");
ptrAutoXGainValueLowerLimit->SetValue([insert lower limit]);
CFloatPtr ptrAutoXGainValueUpperLimit = nodeMap.GetNode("AutoExposureGainUpperLimit"); ptrAutoXGainValueUpperLimit->SetValue([insert upper limit]);

// Exposure time limit 
CFloatPtr ptrAutoXExposureTimeLowerLimit = nodeMap.GetNode("AutoExposureExposureTimeLowerLimit");
ptrAutoXExposureTimeLowerLimit->SetValue([insert lower limit]);
CFloatPtr ptrAutoXExposureTimeUpperLimit = nodeMap.GetNode("AutoExposureExposureTimeUpperLimit ");
ptrAutoXExposureTimeUpperLimit->SetValue([insert upper limit]);

Camera priority to maintain gain
Use this mode to minimize noise . Keep the camera gain as low as possible , And adjust the exposure time according to the target gray . If the maximum exposure is reached before reaching the target gray level , Then the gain begins to increase , Until the target gray level is reached .

// Camera priority gain 
CEnumerationPtr ptrAutoXControlPriority = nodeMap.GetNode("AutoExposureControlPriority");
CEnumEntryPtr ptrAutoXControlPriorityGain = ptrAutoXControlPriority->GetEntryByName("Gain");
ptrAutoControlPriority->SetIntValue(ptrAutoXControlPriorityGain->GetValue());

The camera gives priority to maintaining the exposure time
Use this mode to capture quick actions . When selecting it , The camera keeps the exposure time as short as possible , And adjust the gain according to the target gray value . If the maximum gain is reached before reaching the target gray level , Then the exposure time will change , Until the target gray level is reached .

// Give priority to maintaining exposure time 
CEnumerationPtr ptrAutoXControlPriority = nodeMap.GetNode("AutoExposureControlPriority");
CEnumEntryPtr ptrAutoXControlExposureTimePriority = ptrAutoXControlPriority->GetEntryByName("ExposureTime");
ptrAutoControlPriority->SetIntValue(ptrAutoXControlExposureTimePriority ->GetValue());
原网站

版权声明
本文为[The moon shines on the silver sea like a dragon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207061823093143.html