SK91USB3-LX  1.2.0
Functions
Imaging

Describes how to create images. More...

Functions

int SK_MAKE_BITMAP (int CamID, unsigned char *pSource, int bitdepth, int pixel, int lines, bool newBitmap, bool copyData, double brightness, int yMin, int yMax)
 Creates an internal bitmap, converts the camera raw data to this bitmap, and prepares it for display and saving. More...
 
int SK_GET_BITMAPINFO (int CamID, int *width, int *height, int *bitsPerPixel, unsigned char **pImageData)
 Returns the information about the current used bitmap, which was created with SK_MAKE_BITMAP. More...
 
int SK_SAVE_IMAGE (int CamID, const char *fileName)
 Saves the image, which was created by SK_MAKE_BITMAP. More...
 
int SK_READ_IMAGE (int CamID, const char *fileName)
 Loading an image from a file. More...
 
int SK_LINESPACECORRECTION (int CamID, unsigned char *pDestination, unsigned char *pSource, int bitdepth, int iPixel, int iLines, double factor, int direction)
 Corrects the line spacing between RGB distances of camera raw data. More...
 
int SK_SEPARATECOLORS (int CamID, void *pRed, void *pGreen, void *pBlue, void *pSource, int bitdepth, int pixelsAtLine, int iLines)
 Splits the RGB signal of the color line scan camera in three different buffers. More...
 

Detailed Description

Describes how to create images.

Introduction

This module contains various functions for creation, display, saving and loading of images from camera raw data. The function SK_MAKE_BITMAP converts the raw data to a bitmap format, and prepares it for display and saving. The function SK_GET_BITMAPINFO returns information about the bitmap, like dimension, bit depth, and the pointer to bitmap data. The storing of a bitmap is possible with SK_SAVE_IMAGE, SK_READ_IMAGE loads a bitmap from file into an internal bitmap buffer for display.

In the following subsection is the creation and saving of an gray scaled image described.

Create and save a grayscale image

// initialize everything
// allocate memory for 2048 lines
SK_ALLOC_LINES(m_CamID, 2048, 0);
// grab the image with 2s timeout, noWait = false, no frame sync and free run mode
SK_GRAB(m_CamID, 0, 2000, false, 0, SK_FREERUN);
// build a bitmap from raw data
SK_MAKE_BITMAP(m_CamID, SK_GETBUFFER(m_CamID, 0), SK_GETBITSPERPIXEL(m_CamID), SK_GETBITSPERPIXEL(m_CamID), SK_GET_BUFFER_LINES(m_CamID, 0), false, false, 1.0, 0, SK_GETBITSPERPIXEL(m_CamID) == 8 ? 255 : 4095, NULL);
// variables for bitmap informations
int imageWidth = 0, imageHeight = 0;
unsigned char * imageData = nullptr;
// verify for successful creation of the bitmap, and get bitmap information
if(SK_GET_BITMAPINFO(m_CamID, &imageWidth, &imageHeight, NULL, &imageData) == SK_RESULT_OK)
{
// image processing ...
// save the image
SK_SAVE_IMAGE(m_CamID, "/home/user/test.bmp");
}

Color images

Color line scan cameras with triple line sensor have three different sensor lines for red (R), green (G) and blue (B). Between the sensor lines exists a gap, called line spacing (details are described in the camera manual). The line spacing is sensor specific and, between two color lines, it can be 1 up to 9 times the pixel height. For the correct color mixing in a image the different locations of R, G, and B have to be considered.
This is be done by the function SK_LINESPACECORRECTION. The source data must be the unchanged camera raw data. The result are RGB triple with corrected line spacing, which may be the input for SK_MAKE_BITMAP. Notes:

The extracting of a single color from a RGB color image is possible with SK_SEPARATECOLORS.

Create Color Images

// initialize everything
// allocate memory for 2048 lines
SK_ALLOC_LINES(m_CamID, 2048, 0);
// grab the image with 2s timeout, noWait = false, no frame sync and free run mode
SK_GRAB(m_CamID, 0, 2000, false, 0, SK_FREERUN);
// Correct the line space between the color line sensors with factor = 1.0 and direction = 0
SK_LINESPACECORRECTION(m_CamID, SK_GETBUFFER(m_CamID, 0), SK_GETBUFFER(m_CamID, 0), SK_GETBITDEPTH(m_CamID), SK_GETPIXNUM(m_CamID), SK_GET_BUFFER_LINES(m_CamID, 0), 1.0, 0);
// build the bitmap with newBitmap = false, copyData = false, brightness = 1.0 (no up- or downscaling of intensity), and normal intensity range
SK_MAKE_BITMAP(m_CamID, SK_GETBUFFER(m_CamID, 0), SK_GETBITSPERPIXEL(m_CamID), SK_GETPIXELSPERLINE(m_CamID), SK_GET_BUFFER_LINES(m_CamID, 0), false, false, 1.0, 0, SK_GETBITSPERPIXEL(m_CamID) == 8 ? 255 : 4095, NULL);
// variables for bitmap informations
int imageWidth = 0, imageHeight = 0;
unsigned char * imageData = NULL;
// verify for successful creation of the bitmap, and get bitmap information
if(SK_GET_BITMAPINFO(m_CamID, &imageWidth, &imageHeight, NULL, &imageData) == SK_RESULT_OK)
{
// do the image processing ...
}

Color splitting

The function SK_SEPARATECOLORS splits the red, green, and blue part from a color image or from a single line in separate memories:

// initializations
// m_iLines= 1 // here split the colors from 1 single line
// allocate memory for 1 line
SK_ALLOC_LINES(m_CamID, 1, ID0);
// allocate memories for each color
// ID1 = red, ID2 = green, ID3 = blue
SK_ALLOC_BUFFER(m_CamID, SK_GETPIXELSPERLINE(m_CamID), ID1);
SK_ALLOC_BUFFER(m_CamID, SK_GETPIXELSPERLINE(m_CamID), ID2);
SK_ALLOC_BUFFER(m_CamID, SK_GETPIXELSPERLINE(m_CamID), ID3);
// grab a single line with 2s timeout, noWait = false, no frame sync and free run mode into memory ID0
SK_GRAB(m_CamID, NULL, m_iLines, 2000, false, 0, SK_FREERUN);
// separate the colors for one line
SK_SEPARATECOLORS(m_CamID, (void*)SK_GETBUFFER(m_CamID, ID1), (void*)SK_GETBUFFER(m_CamID, ID2), (void*)SK_GETBUFFER(m_CamID, ID2), SK_GETBUFFER(m_CamID, ID0), SK_GETBITDEPTH(m_CamID), SK_GETPIXNUM(m_CamID), 1);
// SK_GETBUFFER(m_CamID, ID1) = red data
// SK_GETBUFFER(m_CamID, ID2) = green data
// SK_GETBUFFER(m_CamID, ID3) = blue data

Load an image from a file

// initialize everything
SK_READ_IMAGE(m_CamID, "/home/user/test.bmp");
// variables for bitmap informations
int imageWidth = 0, imageHeight = 0;
int bitsPerPixel = 0;
unsigned char * imageData = nullptr;
verify for successful reading of the bitmap, and get the bitmap information for dimension, bit depth, and pointer to image data
if(SK_GET_BITMAPINFO(m_CamID, &imageWidth, &imageHeight, &bitsPerPixel, &imageData) == SK_RESULT_OK)
{
// if (bitsPerPixel == 24)
// --> the loaded file is a color image with 3x 8 bit for RGB
// if (bitsPerPixel == 8)
// --> the loaded file is a grayscale image
// image processing ...
}

Function Documentation

int SK_GET_BITMAPINFO ( int  CamID,
int *  width,
int *  height,
int *  bitsPerPixel,
unsigned char **  pImageData 
)

Returns the information about the current used bitmap, which was created with SK_MAKE_BITMAP.

Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
[out]widthpointer for the width of the bitmap
[out]heightpointer for the height of the bitmap
[out]bitsPerPixelpointer for the bits per pixel / bit depth of the bitmap
[out]pImageDatapointer for the image data of the bitmap
Returns
SK_RESULT_OK on success, else see Error Code Table
int SK_LINESPACECORRECTION ( int  CamID,
unsigned char *  pDestination,
unsigned char *  pSource,
int  bitdepth,
int  iPixel,
int  iLines,
double  factor,
int  direction 
)

Corrects the line spacing between RGB distances of camera raw data.

Triple line color cameras have a Line Spacing between R, G, and B sensor line from 1 up to 9 times the pixel height. This function corrects the RGB distances in a grabbed image. The result is a RGB matched data matrix in the destination buffer. Furthermore the wrong transport direction can be corrected.

Between the sensor lines exists a gap, called line spacing (details are described in the camera manual). The line spacing is sensor specific and, between two color lines, it can be 1 up to 9 times the pixel height. For the correct color mixing in a image the different locations of R, G, and B have to be considered.
This is be done by the function SK_LINESPACECORRECTION. The source data must be the unchanged camera raw data. The result are RGB triple with corrected line spacing, which may be the input for SK_MAKE_BITMAP. Notes:

Example for using this function: Create Color Images

Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
pDestinationdestination buffer
pSourcesource data array, must be unchanged raw data
bitdepthbit depth of source data (e.g. 8 or 12 bit)
iPixelnumber of pixels per line
iLinesnumber of lines
factorfactor for modify the default line spacing, usable in case of wrong transport velocity, default = 1.0
direction0= scan in preferably direction
else against this
Returns
SK_RESULT_OK on success, else see Error Code Table
int SK_MAKE_BITMAP ( int  CamID,
unsigned char *  pSource,
int  bitdepth,
int  pixel,
int  lines,
bool  newBitmap,
bool  copyData,
double  brightness,
int  yMin,
int  yMax 
)

Creates an internal bitmap, converts the camera raw data to this bitmap, and prepares it for display and saving.

With the input parameter brightness, it is possible to down or upscale the intensities of the image. A brightness of 0 (zero) generates a black image!

Normally, the input parameters yMin and yMax are from 0 to 255 (8 bit) or 4095 (12 bit). But it is possible to use these parameters for a manual histogram stretching.
For example: If yMin is set to 70 and yMax to 128, then the functions spreads the intensities which have normally a range from 58 stages, to 255 stages.

Example for creating grey scaled image: Create and save a grayscale image
Example for creating color image: Create Color Images

Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
pSourcepointer to camera raw data
bitdepthADC resolution, valid values: 8 or 12
pixelnumber of pixel, image width
linesnumber of lines, image height
newBitmaptrue = creates new bitmap
false = using of existing bitmap structure (lines, pixel, color space), image data will be refreshed
copyDatatrue = only for monochrome cameras, the raw data will be copied directly into the bitmap, the result is a grayscale image
false = must be set for color camera, the raw data will be sorted to a bitmap compliant alignment, the result is a color image
brightnessbrigthness factor, which the intensity is multiplied, default= 1.0, > 1.0 image is brighter, < 1.0 image is darker
yMinthe intensity range between yMin and yMax will be scaled by a linear spreading to full grayscale range, which depends on the ADC resolution, yMin: default 0, maximum yMax-1
yMaxupper intensity for spreading, at 8 bit: maximum 255, at 12 bit: maximum 4095. Values for yMin > 0 and yMax < maximum increase the contrast of the image.
Returns
SK_RESULT_OK on success, else see Error Code Table

GV::instance()->m_pCam[CamID]->privat[sk_bytesPerPixel]

int SK_READ_IMAGE ( int  CamID,
const char *  fileName 
)

Loading an image from a file.

Example for loading gray scaled image: Load an image from a file

Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
fileNamefile name
Returns
SK_RESULT_OK on success, else see Error Code Table
int SK_SAVE_IMAGE ( int  CamID,
const char *  fileName 
)

Saves the image, which was created by SK_MAKE_BITMAP.

Example for saving gray scaled image: Create and save a grayscale image

Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
fileNamefile name
Returns
SK_RESULT_OK on success, else see Error Code Table
int SK_SEPARATECOLORS ( int  CamID,
void *  pRed,
void *  pGreen,
void *  pBlue,
void *  pSource,
int  bitdepth,
int  pixelsAtLine,
int  iLines 
)

Splits the RGB signal of the color line scan camera in three different buffers.

Example for using this function: Color splitting

Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
pRedpointer to pointer of red result array
pGreenpointer to pointer of green result array
pBluepointer to pointer of blue result array
pSourcepointer to source data
bitdepthbit depth of the source data, valid values 8 or 12 bit
pixelsAtLineall pixels per line
iLinesnumber of lines for separation
Returns
SK_RESULT_OK on success, else see Error Code Table