Class ImageBufferExtensionsHalconDotNet
Contains extension methods for ImageBuffer for interop with the MVTec.HalconDotNet library (https://mvtec.com/).
Inherited Members
Namespace: ic4
Assembly: ic4dotnet.HalconDotNet.dll
Syntax
public static class ImageBufferExtensionsHalconDotNet
Examples
Since the members are extension methods, they can be called both explicitly and on image buffers directly, as if they were member functions.
To call it as a member function, a using
directive has to exist for the ic4
namespace:
using ic4;
// (...)
// Get image buffer from somewhere
ImageBuffer imageBuffer = GetImageBuffer();
// Create copy in a HImage object
HImage img = imageBuffer.CreateHImageCopy();
Although not preferred, the function can also be called explicitly:
// Get image buffer from somewhere
ImageBuffer imageBuffer = GetImageBuffer();
// Create copy in a HImage object
HImage img = ImageBufferExtensionsHalconDotNet.CreateHImageCopy(imageBuffer);
Methods
CopyFrom(ImageBuffer, HImage)
Copies the contents of a HALCON HImage
into this ImageBuffer.
Declaration
public static void CopyFrom(this ImageBuffer buffer, HImage src)
Parameters
Type | Name | Description |
---|---|---|
ImageBuffer | buffer | An image buffer |
HImage | src | An Halcon |
Remarks
The image type of buffer
needs to match the dimensions and type of src
.
- If
src
is a 1-channel image of typebyte
,buffer
must be Mono8 of the same size. - If
src
is a 1-channel image of typeuint2
,buffer
must be Mono16 of the same size. - If
src
is a 3-channel image of typebyte
,buffer
must be BGRa8 of the same size. - If
src
is a 3-channel image of typeuint2
,buffer
must be BGRa16 of the same size. - Other image types are not supported.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
NotSupportedException | The type of |
ArgumentException | T image type of |
CreateHImageCopy(ImageBuffer)
Creates a copy of the image buffer's data and stores it in a HImage
.
Declaration
public static HImage CreateHImageCopy(this ImageBuffer buffer)
Parameters
Type | Name | Description |
---|---|---|
ImageBuffer | buffer | An image buffer |
Returns
Type | Description |
---|---|
HImage | A |
Remarks
The image format of the `HImage` depends on the pixel format of the image buffer:
- Mono8 image buffers are returned in a single-channel
byte
image. - Monochrome image buffers with more than 8 bits per pixel (e.g. Mono12p) are converted and returned in a single-channel
uint2
image. - 8-bit Bayer image buffers (e.g. BayerBG8) are converted to a 3-channel
byte
image. - Bayer image buffers with more than 8 bits per pixel (e.g. BayerGB12p) are converted to a 3-channel
uint2
image. - BGRa16 image buffers are returned as a 3-channel
uint2
image. - Any other color image buffer (e.g. BGRa8) are returned in a 3-channel
byte
image.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
NotSupportedException | The pixel format of the image buffer is not supported. |
CreateHImageWrap(ImageBuffer)
Wraps the passed image buffer in a HImage
.
Declaration
public static HImage CreateHImageWrap(this ImageBuffer buffer)
Parameters
Type | Name | Description |
---|---|---|
ImageBuffer | buffer | An image buffer |
Returns
Type | Description |
---|---|
HImage | A |
Remarks
Check IsHImageWrapSupported(ImageBuffer) to find out whether wrapping the image buffer is possible.
Wrapping the contents of an image buffer in a HImage
is only possible
if the pixel format is one of the following:
There must not be any horizontal padding in the image buffer. Pitch must be equal to the image's width times the bytes per pixel of the image's pixel format.
The returned HImage
objects maintains a reference to the passed image buffer, preventing it from being
reused until the HImage
object is disposed (or garbage collected).
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
NotSupportedException | Data of the image buffer's pixel format cannot be wrapped in a |
CreateImageBufferCopy(HImage)
Copies the contents of an HALCON HImage
into a new ImageBuffer.
Declaration
public static ImageBuffer CreateImageBufferCopy(this HImage src)
Parameters
Type | Name | Description |
---|---|---|
HImage | src | An HALCON |
Returns
Type | Description |
---|---|
ImageBuffer | A new image buffer containing a copy of the contents of |
Remarks
The resulting image buffer's pixel format depends on the type of src
:
- If
src
is a 1-channel image of typebyte
, the pixel format for the returned image buffer is Mono8. - If
src
is a 1-channel image of typeuint2
, the pixel format for the returned image buffer is Mono16. - If
src
is a 3-channel image of typebyte
, the pixel format for the returned image buffer is BGRa8. - If
src
is a 3-channel image of typeuint2
, the pixel format for the returned image buffer is BGRa16. - Other image types are not supported.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
NotSupportedException | The type of the |
CreateImageBufferCopy(HImage, BufferPool)
Copies the contents of an HALCON HImage
into a new ImageBuffer.
Declaration
public static ImageBuffer CreateImageBufferCopy(this HImage src, BufferPool pool)
Parameters
Type | Name | Description |
---|---|---|
HImage | src | An HALCON |
BufferPool | pool | A buffer pool to query the new image buffer from |
Returns
Type | Description |
---|---|
ImageBuffer | A new image buffer containing a copy of the contents of |
Remarks
The resulting image buffer's pixel format depends on the type of src
:
- If
src
is a 1-channel image of typebyte
, the pixel format for the returned image buffer is Mono8. - If
src
is a 1-channel image of typeuint2
, the pixel format for the returned image buffer is Mono16. - If
src
is a 3-channel image of typebyte
, the pixel format for the returned image buffer is BGRa8. - If
src
is a 3-channel image of typeuint2
, the pixel format for the returned image buffer is BGRa16. - Other image types are not supported.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
NotSupportedException | The type of the |
IsHImageWrapSupported(ImageBuffer)
Checks whether CreateHImageWrap(ImageBuffer) can be used with the passed image buffer.
Declaration
public static bool IsHImageWrapSupported(this ImageBuffer buffer)
Parameters
Type | Name | Description |
---|---|---|
ImageBuffer | buffer | An image buffer |
Returns
Type | Description |
---|---|
bool |
|
Remarks
Wrapping the contents of an image buffer in a HImage
is only possible
if the pixel format is one of the following:
There must not be any horizontal padding in the image buffer. Pitch must be equal to the image's width times the bytes per pixel of the image's pixel format.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|