Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

First, the step defines the data layout of the array a. It shouldn't be used for element access. a.step[0] gives you the number of bytes needed to store a line (first dimension); a.step[1] for a pixel (second dimension), a.step[2] for the third dimension (channel).

Images don't have to be continuous. Large images can be split up to better fit in the memory. Lines are always stored in a continuous memory block (step[0] bytes).

As a general rule, it's better to consider matrices as non-continuous and use the ptr function to get the address of a line. To access an element (x,y), you should use (considering that you have an element size of 1):

a.ptr(y)+x

instead of

a.data()+y*a.cols()+x