SK91USB3-LX  1.2.0
Functions
Gain / Offset Control

Explains how to control the camera gain / offset. More...

Functions

int SK_SETGAINCOUPLING (int CamID, bool enable)
 Coupling of gain channels. More...
 
int SK_SETGAIN (int CamID, int gain, int channel)
 Gain control. More...
 
int SK_SETOFFSET (int CamID, int offset, int channel)
 Offset control. More...
 
int SK_GETGAIN (int CamID, int channel)
 Returns the current gain value of a ADC channel. More...
 
int SK_GETOFFSET (int CamID, int channel)
 Returns the current offset value (black level) for the defined ADC channel. More...
 
int SK_GETNROFCHANNELS (int CamID)
 Returns the camera specific number of ADC channels. More...
 

Detailed Description

Explains how to control the camera gain / offset.

The line scan camera is provided with correctly adjusted gain / offset. Only if necessary, these settings should be changed. This must be done carefully.

The number of channels for gain and offset is sensor specific and depends on the number of ADCs inside of the camera. The number of channels is returned by the function SK_GETNROFCHANNELS. The setting range for gain is 0 to 1023 (0 db to 24 db), the offset setting range is 0 to 255.
Note: Too low gain values (< 80) can reduce the signal dynamic by limiting the input range of the ADC. Very high gain values increase the noise.

Re-Adjustment principle

Normally, to re-adjust the gain / offset setting use the SKLineScan program with the manual for SKLineScan.
If this is not possible, here is an example to display the oscilloscope signal with the library OpenCV:

#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
// init the camera, allocate memory, etc..
// create new OpenCV image with one line and number of pixels at the sensor as cols for 8 bit monochrome camera
cv::Mat image = cv::Mat(1, SK_GETPIXELSPERLINE(m_CamID), CV_8UC1);
// endless grab
while(true)
{
// grab one line with timeout of 10s in the memory m_data with no frame sync and line sync
SK_GRAB(m_CamID, m_data, 1, 10000, true, 0, SK_FREERUN);
for(int i = 0; i < SK_GETPIXELSPERLINE(m_CamID) - 1; i++)
cv::line(image, cv::Point(i, m_data[i]), cv::Point(i, m_data[i + 1]), cv::Scalar(255), 1);
// display the oscilloscope signal
cv::imshow("Oscilloscope Signal", image);
// refresh the screen (do not wait)
cv::waitKey(10);
// set all image pixels to black
image = cv::Scalar(0);
}

1. Offset (using the SK2048U3PD)
The zero baselines of the video signal 1 and 2 must be adjusted and balanced. To do this, totally block the incident light and execute the function SK_SETOFFSET(m_CamID, 0, 0) and SK_SETOFFSET(m_CamID, 1, 0).
Minimize any differences using the function SK_SETOFFSET.
A slight signal noise should be visible in the zero baseline.

Adjust_Offset.png

2. Gain (using SK2048U3PD)

Illuminate the sensor with a slight over exposure to identify the maximum clipping. Use the function SK_SETGAIN(m_CamID, 0, XX) (XX = gain value) to adjust the maximum output voltage for the first channel. Adjust the signal intensity with the function SK_SETGAIN(m_CamID, 1, XX) (XX = gain value) to minimize the difference between channels 0 and 1.

Notes for gain adjustment:

Adjust_Gain_1.png
Adjust_Gain_2.png

Function Documentation

int SK_GETGAIN ( int  CamID,
int  channel 
)

Returns the current gain value of a ADC channel.

Remarks
The number of ADC channels is camera specific and can be inquire by SK_GETNROFCHANNELS.
Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
channelADC channel
Returns
gain value, else see Error Code Table
int SK_GETNROFCHANNELS ( int  CamID)

Returns the camera specific number of ADC channels.

Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
Returns
number of ADC channels, else see Error Code Table
int SK_GETOFFSET ( int  CamID,
int  channel 
)

Returns the current offset value (black level) for the defined ADC channel.

Remarks
The number of ADC channels is camera specific and can be inquire by SK_GETNROFCHANNELS.
Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
channelADC channel
Returns
offset value, else see Error Code Table
int SK_SETGAIN ( int  CamID,
int  gain,
int  channel 
)

Gain control.

This function sets the gain value for the defined ADC channel.

The number of ADC channels is camera specific and can be inquire by SK_GETNROFCHANNELS or the camera manual.

Note
Range of values: 0 ... 1023, 1023 = 24 dB
Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
gaingain value
channelADC Channel
Returns
SK_RESULT_OK on success, else see Error Code Table
int SK_SETGAINCOUPLING ( int  CamID,
bool  enable 
)

Coupling of gain channels.

This function is suitable for cameras with more than one ADC channel. Once adjusted, all gain channels can be coupled and will be controlled together by channel 0 only. The differences between the channels before coupling are changed proportionally.

Remarks
Together with SK_NOSAVINGEEPROM with enable = false this function is usable for a very fast changes of gain adjustment. While Continuous Grabbing all parameter settings are blocked normally. A backdoor for gain setting between two frames is SK_SETCOMMAND(CamID, "Gnnnn", nullptr, 1), wherein all gain channels should be coupled.

Calculation of proportional changing of gain channel differences inside the camera: before coupling: gain channel 0: G0= 108, gain channel 1: G1= 110
new gain G' with coupled channels
camera revision < 1.22: G0'= 212, G1'= G0' + (G1 - G0) = 214
camera revision >= 1.22: G0'= 212, G1'= G0' * G1/G0 = 216

Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
enabletrue = gain coupling is active
false = gain coupling is not active
Returns
SK_RESULT_OK on success, else see Error Code Table
int SK_SETOFFSET ( int  CamID,
int  offset,
int  channel 
)

Offset control.

This function sets the offset value for the defined ADC channel.

The number of ADC channels is camera specific and can be inquire by SK_GETNROFCHANNELS or the camera manual.

Note
Range of values: 0 ... 255
Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
offsetOffset value
channelADC channel
Returns
SK_RESULT_OK on success, else see Error Code Table