Based on what @J. Calleja said you have two options
Random access
If you want to randomly access a Mat element, just use
at<data_Type>(row_num, col_num) = value;
Continuous access
If you want continuous access, OpenCV provides a Mat iterator compatible with the STL iterator
MatIterator_<double> it, end; for( it = I.begin<double>(), end = I.end<double>(); it != end; ++it) { //do something here }
or
for(int row = 0; row < mat.rows; ++row) { float* p = mat.ptr(row);
I take a picture from a blog post Dynamic two-dimensional arrays in C

Wei Yuang Hsu Oct 27 '17 at 1:46 on 2017-10-27 01:46
source share