SK91USB3-WIN  5.5.0
Functions
Imaging

Additional functions to create and display images from raw data. More...

Functions

void SK_DISPLAY_LINE (int CamID, HDC hDC, PUCHAR source, int n, RECT dwin, int fmin, int fmax, int pixWise)
 Plots an 8-bit line scan signal in an oscilloscopic style. More...
 
void SK_DISPLAY_LINE12 (int CamID, HDC hDC, USHORT *source, int n, RECT dwin, int fmin, int fmax, int pixWise)
 Plots an 12-bit line scan signal in an oscilloscopic style. More...
 
void SK_DISPLAY_TRANSITIONS (int CamID, HDC hDC, unsigned short *source, int p1, int n, RECT dwin, int high, int low)
 Displays a binary plots of a array of transitions. More...
 
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_DISPLAY_IMAGE (int CamID, HDC hDC, int widthOfView, int heightOfView, int x0, int y0, int pixel, int lines)
 Displays the last created bitmap with SK_MAKE_BITMAP. 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_CONVERT_BITMAP (int CamID, PUCHAR pDestination, int dBitsPerPixel, int dPixels, int dLines, PUCHAR pSource, int sBitsPerPixel)
 Coverts the internal bitmap to another format. More...
 
int SK_SAVE_IMAGE (int CamID, LPCTSTR fileName)
 Saves the image, which was created by SK_MAKE_BITMAP. More...
 
int SK_READ_IMAGE (int CamID, LPCTSTR fileName)
 Loading an image from a file. More...
 
int SK_LINESPACECORRECTION (int CamID, PUCHAR pDestination, PUCHAR 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, PVOID pRed, PVOID pGreen, PVOID pBlue, PVOID pSource, int bitdepth, int pixelsAtLine, int iLines)
 Splits the RGB signal of the color line scan camera in three different buffers. More...
 

Detailed Description

Additional functions to create and display images from raw data.

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 grayscale 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, NULL, 1, 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);
// variables for bitmap information
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)
{
// 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);
// 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 information
int imageWidth = 0, imageHeight = 0;
int bitsPerPixel = 0;
unsigned char * imageData = NULL;
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

◆ SK_CONVERT_BITMAP()

int SK_CONVERT_BITMAP ( int  CamID,
PUCHAR  pDestination,
int  dBitsPerPixel,
int  dPixels,
int  dLines,
PUCHAR  pSource,
int  sBitsPerPixel 
)

Coverts the internal bitmap to another format.

Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
pDestinationpointer to the destination buffer
dBitsPerPixeldestination format, 8, 24, 32
dPixelsnumber of pixels, image width
dLinesnumber of lines, image height
pSourcepointer to the source buffer
sBitsPerPixelsource format, 8, 24, 32
Returns
SK_RESULT_OK on success, else see Error Code Table

◆ SK_DISPLAY_IMAGE()

int SK_DISPLAY_IMAGE ( int  CamID,
HDC  hDC,
int  widthOfView,
int  heightOfView,
int  x0,
int  y0,
int  pixel,
int  lines 
)

Displays the last created bitmap with SK_MAKE_BITMAP.

Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
hDCdevice context of the drawing window
widthOfViewwidth of the drawing window
heightOfViewheight of the drawing window
x0start pixel on the x-axis of top left corner
y0start pixel on the y-axis of top left corner
pixelnumber of pixel to display
linesnumber of lines to display
Returns
SK_RESULT_OK on success, else see Error Code Table

◆ SK_DISPLAY_LINE()

void SK_DISPLAY_LINE ( int  CamID,
HDC  hDC,
PUCHAR  source,
int  n,
RECT  dwin,
int  fmin,
int  fmax,
int  pixWise 
)

Plots an 8-bit line scan signal in an oscilloscopic style.

Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
hDCdevice context of the drawing window
sourcepointer to video data
nnumber of pixel per line
dwindrawing range inside of the hDC owner window
fminscale minimum
fmaxscale maximum
pixWise1 = draw pixel intensity as bars (square)
0 = connect pixel intensities (round)
Returns
SK_RESULT_OK on success, else see Error Code Table

◆ SK_DISPLAY_LINE12()

void SK_DISPLAY_LINE12 ( int  CamID,
HDC  hDC,
USHORT *  source,
int  n,
RECT  dwin,
int  fmin,
int  fmax,
int  pixWise 
)

Plots an 12-bit line scan signal in an oscilloscopic style.

Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
hDCdevice context of the drawing window
sourcepointer to video data (12 bit)
nnumber of pixel per line
dwindrawing range inside of the hDC owner window
fminscale minimum
fmaxscale maximum
pixWise1 = draw pixel intensity as bars (square)
0 = connect pixel intensities (round)
Returns
SK_RESULT_OK on success, else see Error Code Table

◆ SK_DISPLAY_TRANSITIONS()

void SK_DISPLAY_TRANSITIONS ( int  CamID,
HDC  hDC,
unsigned short *  source,
int  p1,
int  n,
RECT  dwin,
int  high,
int  low 
)

Displays a binary plots of a array of transitions.

Parameters
CamIDid of camera from 0 ... n - 1, 0 = 1st camera
hDCdevice context of the drawing window
sourceunsigned short pointer to transitions
p1start pixel for display
nnumber of displayed pixel
dwindrawing range inside of the hDC owner window
highintensity for high level
lowintensity for low level
Returns
SK_RESULT_OK on success, else see Error Code Table

◆ SK_GET_BITMAPINFO()

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 to width
[out]heightpointer to height
[out]bitsPerPixelpointer to bits per pixel
[out]pImageDatapointer to the image data
Returns
SK_RESULT_OK on success, else see Error Code Table

◆ SK_LINESPACECORRECTION()

int SK_LINESPACECORRECTION ( int  CamID,
PUCHAR  pDestination,
PUCHAR  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

◆ SK_MAKE_BITMAP()

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.

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 camrera raw data
bitdepthADC resolution, valid values: 8 or 12
pixelnumber of pixel, image width
linesnumber of lines, image height
newBitmaptrue = creates a new bitmap
false = using of existing bitmap structure, the 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

◆ SK_READ_IMAGE()

int SK_READ_IMAGE ( int  CamID,
LPCTSTR  fileName 
)

Loading an image from a file.

Example for loading grayscale 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

◆ SK_SAVE_IMAGE()

int SK_SAVE_IMAGE ( int  CamID,
LPCTSTR  fileName 
)

Saves the image, which was created by SK_MAKE_BITMAP.

Example for saving grayscale 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

◆ SK_SEPARATECOLORS()

int SK_SEPARATECOLORS ( int  CamID,
PVOID  pRed,
PVOID  pGreen,
PVOID  pBlue,
PVOID  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