Class ImageBufferExtensionsOpenCvSharp

Contains extension methods for ImageBuffer for interop with the OpenCvSharp library (https://github.com/shimat/opencvsharp).

Inheritance

ImageBufferExtensionsOpenCvSharp
Namespace: ic4
Assembly: ic4dotnet.OpenCvSharp.dll
Syntax
public static class ImageBufferExtensionsOpenCvSharp
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 OpenCvSharp.Mat object OpenCvSharp.Mat mat = imageBuffer.CreateOpenCvCopy();

Although not preferred, the function can also be called explicitly:

// Get image buffer from somewhere
ImageBuffer imageBuffer = GetImageBuffer();
// Create copy in a OpenCvSharp.Mat object
OpenCvSharp.Mat mat = ImageBufferExtensionsOpenCvSharp.CreateOpenCvCopy(imageBuffer);

Methods

CreateOpenCvCopy(ImageBuffer)

Creates a copy of the image buffer and stores it in a OpenCvSharp.Mat.

Declaration

public static Mat CreateOpenCvCopy(this ImageBuffer buffer)

Parameters

Type Name Description
ImageBuffer buffer

An image buffer

Returns

Type Description
Mat

A OpenCvSharp.Mat containing a copy of the image data in the passed image buffer.

Exceptions

Type Condition
ArgumentNullException

buffer is null

NotSupportedException

The pixel format of the image buffer is not supported.

CreateOpenCvWrap(ImageBuffer)

Wraps the passed image buffer in a OpenCvSharp.Mat.

Declaration

public static Mat CreateOpenCvWrap(this ImageBuffer buffer)

Parameters

Type Name Description
ImageBuffer buffer

An image buffer

Returns

Type Description
Mat

A OpenCvSharp.Mat using the image buffer's memory as pixel storage

Exceptions

Type Condition
ArgumentNullException

buffer is null

NotSupportedException

Data of the image buffer's pixel format cannot be wrapped in a OpenCvSharp.Mat.

IsOpenCvWrapSupported(ImageBuffer)

Checks whether CreateOpenCvWrap(ImageBuffer) can work on the image buffer's pixel format.

Declaration

public static bool IsOpenCvWrapSupported(this ImageBuffer buffer)

Parameters

Type Name Description
ImageBuffer buffer

An image buffer

Returns

Type Description
bool

true, if the contents of the image buffer can be wrapped in a OpenCvSharp.Mat, otherwise false.

Remarks

Wrapping the contents of an image buffer in a OpenCvSharp.Mat is only possible if the pixel format is one of the following:

Exceptions

Type Condition
ArgumentNullException

buffer is null