Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, there is: The image is not always continuous in the memory; so mat.data+(y*width+x)*sizeof(elemtype) won't give you the pixel (x,y).

And don't use mat.data, use mat.ptr() of mat.ptr(row) instead!!!

So the last line of the macro should look like:

(elemtype*) (mat.ptr(row) + (sizeof(elemtype)*(col)) )

To access an element directly you should use the standard mat.at<elemtype>(y,x), it's fast.

Yes, there is: The image is not always continuous in the memory; so mat.data+(y*width+x)*sizeof(elemtype) won't give you the pixel (x,y).(x,y). Check if the matrix is continuous with mat.isContinuous().

And don't use mat.data, You can use mat.ptr() of mat.ptr(row) instead!!!instead mat.data (that you can cast directly to another type).

So the last line of the macro should could look like:like (for a more general application):

(elemtype*) (mat.ptr(row) (mat.ptr(row)) + (sizeof(elemtype)*(col)) )
col

I also think (but I might be wrong) that the line pointers are precomputed, so this can save you a multiplication.

To access an element directly you should can use the standard mat.at<elemtype>(y,x), it's also fast.