OpenCV's cv::Mat & CvMat row alignment
could someone pls explain to me how the row alignment of OpenCV's CvMat (or its C++ version cv::Mat ) works? For instance, let's assume I have a matrix CvMat *cvmat = cvCreateMat(2,3,CV_8UC1); cvSet2D( cvmat, 0, 0, cvScalar(1) ); cvSet2D( cvmat, 0, 1, cvScalar(2) ); cvSet2D( cvmat, 0, 2, cvScalar(3) ); cvSet2D( cvmat, 1, 0, cvScalar(4) ); cvSet2D( cvmat, 1, 1, cvScalar(5) ); cvSet2D( cvmat, 1, 2, cvScalar(6) ); According to the documentation of CvMat , rows should be aligned by 4 bytes, i.e. first row of the matrix should be padded by one zero and the second should start at the offset +4).