Ask Your Question

Revision history [back]

Using strided external data in OpenCV

I have an array in memory that represents a matrix. However, I have a stride value for both rows and individual elements. That is, the step from one element in a row to the next is NOT the size associated with its type (e.g. 8 for doubles).

Is there any way to construct a cv::Mat object that maps to this chunk of memory?

P.S. The constructor of cv::Mat with step-size does not seem to do the trick, since I cannot specify the step size between elements in a row.

Using strided external data in OpenCV

I have an array in memory that represents a matrix. However, I have a stride value for both rows and individual elements. That is, the step from one element in a row to the next is NOT the size associated with its type (e.g. 8 for doubles).

Is there any way to construct a cv::Mat object that maps to this chunk of memory?

P.S. The constructor of cv::Mat with step-size does not seem to do the trick, since I cannot specify the step size between elements in a row.

Using strided external data in OpenCVarray as cv::Mat

I have an array in memory that represents a matrix. However, I have a stride value for both rows and individual elements. That is, the step from one element in a row to the next is NOT the size associated with its type (e.g. 8 for doubles).

Is there any way to construct a cv::Mat object that maps to this chunk of memory?

P.S. The constructor of cv::Mat with step-size does not seem to do the trick, since I cannot specify the step size between elements in a row.

Using strided external array as cv::Mat

I have an array in memory that represents a matrix. However, I have a stride value for both rows and individual elements. That is, the step from one element in a row to the next is NOT the size associated with its type (e.g. 8 for doubles).

Is there any way to construct a cv::Mat object that maps to this chunk of memory?

P.S. The constructor of cv::Mat with step-size does not seem to do the trick, since I cannot specify the step size between elements in a row.

Update - data layout

Let's say I have an LxMxN array. It is organized in L-N-M storage order. The following example demonstrates the data layout of a 3x2x2 array in i:(n,m,l) format where i is the actual index in the memory chunk and (n,m,l) is the corresponding index in the 3D array:

0:(0,0,0)  1:(1,0,0)  2:(2,0,0), 
3:(0,1,0)  4:(1,1,0)  5:(2,1,0),
6:(0,0,1)  7:(1,0,1)  8:(2,0,1),
9:(0,1,1) 10:(1,1,1) 11:(2,1,1)

Given such a chunk in memory representing the array A, I would like to construct a cv::Mat object representing, in MATLAB notation, the array A(i,:,:) for a given i.

Using strided external array as cv::Mat

I have an array in memory that represents a matrix. However, I have a stride value for both rows and individual elements. That is, the step from one element in a row to the next is NOT the size associated with its type (e.g. 8 for doubles).

Is there any way to construct a cv::Mat object that maps to this chunk of memory?

P.S. The constructor of cv::Mat with step-size does not seem to do the trick, since I cannot specify the step size between elements in a row.

Update - data layout

Let's say I have an 3D LxMxN array. It stored in a consecutive chunk of memory representing a 1D array of L*M*N entries. The data is organized in L-N-M storage order. The following example demonstrates the data layout of a 3x2x2 array in i:(n,m,l) format where i is the actual index in the memory chunk and (n,m,l) is the corresponding index in the 3D array:

0:(0,0,0)  1:(1,0,0)  2:(2,0,0), 
3:(0,1,0)  4:(1,1,0)  5:(2,1,0),
6:(0,0,1)  7:(1,0,1)  8:(2,0,1),
9:(0,1,1) 10:(1,1,1) 11:(2,1,1)

Given such a chunk in memory representing the 3D array A and a number i, I would like to construct a cv::Mat object representing, in MATLAB notation, the array A(i,:,:) for a given irepresenting a 2D array B such that B(m,n) maps to the same memory cell as A(i,m,n).