Inherits Mat.

Public Types

enum ColorType

Public Member Functions

template<class T >
OpenCvMat(const T* matOrImg)
OpenCvMat(const va_image* img, ColorType colorType)
OpenCvMat(va_image* img, ColorType colorType)

Detailed Description

A class that wraps a va_image or a va_matrix to an OpenCV matrix (cv::Mat) so that the C types are usable in OpenCV calls. This is a non-copyable class that is intended to be used as a temporary wrapper in function calls.

Due to the lack of a standard ABI for C++, the implementation of this class cannot be used from a precompiled library but must be compiled into the calling code. To use the class you must thus add into your project's source files.

OpenCV's cv::Mat class does not implement the copy-on-write paradigm that is the standard convention on reference-counted objects elsewhere. Therefore, the contents of a wrapped image or a matrix may be modified if the called function modifies the data, even though the image or matrix was originally passed as a const pointer. To make things worse, OpenCV function declarations don't use const to distinguish between input and output data, and the documentation isn't always clear on this either. There is no efficient way around this deficiency, so be careful. Make a deep copy of the va_image or va_matrix if unsure.


using VisionAppster::OpenCvMat;
void gaussianBlur(const va_image* input,
int filterSize,
va_image* output)
filterSize |= 1; // Make odd
cv::Size(filterSize, filterSize),
0, 0);
void filter2d(const va_image* input,
const va_dmatrix* kernel,
va_image* output)
-1, // Default color channel depth

Member Enumeration Documentation

OpenCV color types to which automatic conversions from va_image are supported.


Any one-channel (gray level) color type.


24-bit RGB color type (BGR).


32-bit RGB color type (BGRA).

Constructor & Destructor Documentation

template<class T >
OpenCvMat::OpenCvMat (const T* matOrImg) inline

Constructs a cv::Mat that contains a reference to the data in matOrImg, which may be either a va_image or any va_matrix type.

OpenCvMat::OpenCvMat (const va_image* img, ColorType colorType )

Creates a cv::Mat with the specified color type. If the number of color channels in img is not the same as in colorType, a deep copy of the data in img will be created.

Some (but not all) OpenCV functions assume that the input image has three channels instead of four and throw an error if a four-channel image is used. This is unfortunate as it places the responsibility of choosing the correct number of channels to the caller. This constructor can be used in such situations. It can also automatically convert a gray-level image to RGB and vice versa.

OpenCvMat::OpenCvMat (va_image* img, ColorType colorType )

Creates a cv::Mat with the specified OpenCV color type. If the number of color channels in img is not the same as in the target color type, a deep copy of the data in img will be created.

When an OpenCvMat is constructed this way, the temporary copy is automatically copied back to img when the OpenCvMat object goes out of scope. Thus, any modifications made to the temporary image in a function call are propagated to img.

using VisionAppster::OpenCvMat;
// floodFill accepts only 3- and 1-channel images.
// Assuming inImg is 32-bit RGB
va_image* pFilled = va_image_clone(inImg);
cv::floodFill(OpenCvMat(pFilled, OpenCvMat::Rgb24),
cv::Point(100, 100),
cv::Scalar(127, 0, 19));
// pFilled now contains the result in 32-bit RGB