Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you want to "fill the container with your frame" then there is now way around allocating matrix and copying your data into that matrix. However, if you just want to wrap your data pointer by a cv::Mat object (provided that the data organization of this kind makes sense) you can simply call the wrapper constructor:

//! constructor for matrix headers pointing to user-allocated data
Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP);

You can wrap you frame as simple as

Mat wrapped(MatrixRows, MatrixCols, MatrixType, MyDataBuffer);

If you then want to obtain a real copy it is probabl the easiest to do

Mat copy = wrapped.clone();

See also http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-mat

If you want to "fill the container with your frame" then there is now no way around allocating matrix and copying your data into that matrix. However, if you just want to wrap your data pointer by a cv::Mat object (provided that the data organization of this kind makes sense) you can simply call the wrapper constructor:

//! constructor for matrix headers pointing to user-allocated data
Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP);

You can wrap you your frame as simple as

Mat wrapped(MatrixRows, MatrixCols, MatrixType, MyDataBuffer);

If you then want to obtain a real copy it is probabl probably the easiest to do

Mat copy = wrapped.clone();

See also http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-mat

If you want to "fill the container with your frame" then there is no way around allocating matrix and copying your data into that matrix. However, if you just want to wrap your data pointer by a cv::Mat object (provided that the data organization of this kind makes sense) you can simply call the wrapper constructor:

//! constructor for matrix headers pointing to user-allocated data
Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP);

You can wrap your frame as simple as

Mat wrapped(MatrixRows, MatrixCols, MatrixType, MyDataBuffer);

Note that the destruction of wrapped does not free your buffer! You need to manage the underlying memory yourself.

If you then want to obtain a real copy it is probably the easiest to do

Mat copy = wrapped.clone();

See also http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-mat