Access value with a pointer in Mat [closed]
A Mat element is stored in Mat data pointer described in OpenCV document, and the address is mat.data + i0 * mat.step[0] + i1 * mat.step[1] +... + (id-1) * mat.step[id - 1] . I want to access and re-assign an element with data pointer like this:
cv::Mat test = (cv::Mat_<uchar>(3,3) << 1,2,3,4,5,6,7,8,9);
*(test.data + 2 * test.step[1]) = *test.data + 10;
if the element type of Mat is uchar, the code above works well, and the third element is re-assigned as 11, but if the type is not uchar, such as double, the code above does not work, I'm confused about this, please help me.
For one pixel you can use pointer access :
it's better llike this
what are you trying to achieve here ? what is the purpose of your program ?
(in general, you probably should avoid raw pointers, and use higher level opencv functions instead)
Thank you very much. I'm a beginner in OpenCV. I just want to test the pointer data, I will follow your advice to use ptr pointer later.
I forgot this tutorials https://docs.opencv.org/trunk/db/da5/...