Copy cv::Mat into cv::MatND?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Copy cv::Mat into cv::MatND?

Matthias Schmieder
Hi there,
I'm trying to find out how to copy 2-dimensional cv::Mat data into a three-dimensional cv::MatND array right now. What I want to do is to put "n" arrays of size "width x height" into a MatND array of size "n x height x width".

The only way I found until now is to copy pixel by pixel into the MatND-array:

<quote>
std::vector<Mat_<int>> data;
[...]
cont int dim[] = {n, height, width};
cv::MatND_<int> mND(3, dim);

for(int z = 0; z < m_mat->size[1]; z++)
{
   for(int y = 0; y < m_mat->size[1]; y++)
   {
        for(int x = 0; x < m_mat->size[2]; x++)
        {
           (*m_mat)(z,y,x) = data[z](y,x);
        }
   }
}
</quote>

Isn't there a better way to do this. Other array types, like blitz or Matlab, allow to define a range and simply copy a hole buffer into it. Something like this

<quote>
matND.setRange(n,Range::All, Range::All) = data.buffer;
</quote>

Is it possible to do anything like this in OpenCV with MatNDs too?

Any hint is appreciated!

Thanks in advance
Matthias