Leaper Vision Toolkit
中文 / English 2.x
Public Member Functions | Properties
ILImage Interface Reference

This interface expose APIs to access/manipulate/draw a LPV LImage object. More...

Inheritance diagram for ILImage:
ILObject LImage

Public Member Functions

void CopyFrom (ILImage *img, ILRegion *region, int panX, int panY)
 
void CopyTo (ILImage *dstImg)
 
void Draw (HDC hdc, double zoomX, double zoomY, double panX, double panY)
 
void DrawAsMask (HDC hdc, double zoomX, double zoomY, double panX, double panY)
 
ILImageGetChannel (int channelIdx)
 
LPVErrorCode LoadRawFile (LString filename, int w, int h, int flags)
 
LPVErrorCode Save (LString filename, ILRegion *region)
 
void SetChannel (int channelIdx, ILImage *channelImage)
 
void SetImageData (int w, int h, LPVOID dataPtr, int bpl, BOOL copyData)
 
void SetSize (int w, int h)
 
void SetTo (int val, ILRegion *region)
 
void SetToColor (LColor val, ILRegion *region)
 
- Public Member Functions inherited from ILObject
ILObjectCopy ()
 
LPVErrorCode Load (LString filename)
 
void Reset ()
 
LPVErrorCode Save (LString filename)
 
BOOL Valid ()
 

Properties

int BytesPerLine [get]
 The number of bytes contained in a row, include the padding bytes.
 
LPVOID DataPointer [get]
 The pointer to the image data buffer. Please DON'T change the content of the data block.
 
int Height [get]
 The height of the image, number of rows.
 
LPVImageFormat ImageFormat [get, set]
 The format of the image.
 
int Pixel (int x, int y) [get, set]
 
LColor PixelColor (int x, int y) [get, set]
 
int Width [get]
 The width of the image, number of columns.
 

Detailed Description

This interface expose APIs to access/manipulate/draw a LPV LImage object.

Image is the core object in a vision system. The image class encapsulate all the functionality needed to represent a rectangular shaped image. It stores pixels as a 2-dimensional dense array, row by row.

To use this interface, you should create a LImage object.

There are many different ways to initialize data of the image. The most popular options are listed below:

  1. Load image from file via ILImage::Load().
  2. Set image data for data pointer via ILImage::SetImageData(), typically you may get this pointer from camera's callback function.
  3. Set image size as wanted, then assign pixel values one by one manually. But please noted, this way is not efficient.

Example Code

Member Function Documentation

◆ CopyFrom()

void CopyFrom ( ILImage img,
ILRegion region,
int  panX,
int  panY 
)

Copy the content of the input image and cover the current.

Parameters
[in]imgThe input image. If the input image is bigger or outside with the given x/y offset, the redundant part will be ignored.
[in]regionThe input region to crop the input image. Optional, could be null.
[in]panXThe x-coordinate of the offset
[in]panYThe y-coordinate of the offset

◆ CopyTo()

void CopyTo ( ILImage dstImg)

Copy the image object to destination.
If the current image object has its own data buffer, we'll do another clone of data to the destination image object. Otherwise, we just simply assign the data pointer to it.

Parameters
[out]dstImgThe destination image object.

◆ Draw()

void Draw ( HDC  hdc,
double  zoomX,
double  zoomY,
double  panX,
double  panY 
)

Draw the image onto the provided device context.

See also
DrawAsMask()
Use Draw Functions
Remarks
This function is currently not available on Linux / MacOS platform.

◆ DrawAsMask()

void DrawAsMask ( HDC  hdc,
double  zoomX,
double  zoomY,
double  panX,
double  panY 
)

Draw the image as a mask onto the provided device context, white pixels preserve the original values on HDC.

See also
Draw()
Use Draw Functions
Remarks
This function is currently not available on Linux / MacOS platform.

◆ GetChannel()

ILImage* GetChannel ( int  channelIdx)

Extract the channel of the given index. This function is only for a color image.

Parameters
[in]channelIdxThe input channel index, 0, 1 or 2.
Return values
channelImage Return the channel image. It's a grayscale image of the same size as the current color image.

◆ LoadRawFile()

LPVErrorCode LoadRawFile ( LString  filename,
int  w,
int  h,
int  flags 
)

Load image from .raw file.

Parameters
[in]wThe width of the image in pixels, should be a positive value. Since .raw format does not include informations for image size, the caller should set the size manually.
[in]hThe height of the image in pixels, should be a positive value.
[in]flagsControls how to parse the raw data
FlagsUsage
0Each pixel in 16 bits
1Two MONO-12 pixels are packed into 24 bits, the low-4 bits of two pixels encapsulated into a 8 bits
[in]filenameFull path of the file, it could be absolute or relative path with file name and extension.
Return values
errorReturn error code if anything is wrong.
See also
Load()
Since
2.7.0

◆ Save()

LPVErrorCode Save ( LString  filename,
ILRegion region 
)

Save the image object to a specified file. The image format is chosen based on the filename extension. Currently, we support save as BMP, PNG, JPG, JPEG formats.

Parameters
[in]regionOptional, could be null. If you want to only save part of the image, pass in a region.
[in]filenameFull path of the file, it could be absolute or relative path with file name and extension.
Return values
errorReturn error code if anything is wrong.
See also
Save(), Load()

◆ SetChannel()

void SetChannel ( int  channelIdx,
ILImage channelImage 
)

Set the channel of the given index to the input grayscale image. This function is only for a color image.

Parameters
[in]channelIdxThe input channel index, 0, 1 or 2.
[in]channelImage The input grayscale channel image, it should be of the same size as the current color image.

◆ SetImageData()

void SetImageData ( int  w,
int  h,
LPVOID  dataPtr,
int  bpl,
BOOL  copyData 
)

Assign data to the image object via an external allocated buffer.
If copyData is set to False, this pointer overwrite the internally allocated buffer inside the image object. You should take the responsibility to keep the buffer alive during the entire life cycle of the image object.
If copyData is set to True, we'll copy the content into the buffer owned by the image object. You don't need to worry about the data life cycle then.

Parameters
[in]wThe width of the image in pixels, should be a positive value.
[in]hThe height of the image in pixels, should be a positive value.
[in]dataPtrPointer to the external image data buffer.
[in]bplBytes per line, the number of bytes contained in a row. The value should include the padding bytes. at the end of each row, if any. If set to 0, no padding is assumed and the actual stride is calculated as column number * pixel size(sizeof(char)).
[in]copyDataWhether to copy the data into owned buffer of the image object.

◆ SetSize()

void SetSize ( int  w,
int  h 
)

Change the size of image to provided size. The pixel values are undefined. You may set them all to 0 or other preferred value via SetTo() or SetToColor(). If the image is already of the same, we keep the old data. Pass in 0 width or 0 height to reset the image to be empty.

Parameters
[in]wRequired image width.
[in]hRequired image height.

◆ SetTo()

void SetTo ( int  val,
ILRegion region 
)

Set the pixels in the given region to the specified grayscale value. For a color image, all its channels are set to the same value.

Parameters
[in]valThe grayscale value
[in]regionThe input region. If the input region is bigger or outside of the image, the redundant part will be ignored. Optional, could be null, which mean the entire image.

◆ SetToColor()

void SetToColor ( LColor  val,
ILRegion region 
)

Set the pixels in the given region to the specified RGB color value. This function is only for a color image.

Parameters
[in]valThe color value
[in]regionThe input region. If the input region is bigger or outside of the image, the redundant part will be ignored. Optional, could be null, which mean the entire image.

Property Documentation

◆ Pixel

int Pixel
getset

The pixel's grayscale value.

Parameters
[in]xThe x-coordinate of the pixel.
[in]yThe y-coordinate of the pixel.

◆ PixelColor

LColor PixelColor
getset

The pixel's color value.

Parameters
[in]xThe x-coordinate of the pixel.
[in]yThe y-coordinate of the pixel.