Table of Contents
问题需求:获取Mat stride
如题,需要使用到Mat类型的步长stride。
先从本地读取一张图片,单步进去看到srcImage的属性如下图,有stride,也有width,height,channels等
我们可以通过srcImage.cols或者srcImage.size().width来获取图片的宽度,
通过srcImage.channels()来获取通道数量,
通过srcImage.type()来获取图片类型,
但是怎么获取图片的stride呢?
这两种方式
srcImage.stride
或者
srcImage.stride()
都是不对的,
编译器会报错:“Error:class "cv::Mat" has no member "stride"”。
怎么办?
官方资料解释
去OpenCV头文件里只找到这一段话:【位于mat.hpp里】
So, the data layout in Mat is fully compatible with CvMat, IplImage, and CvMatND types from OpenCV
1.x. It is also compatible with the majority of dense array types from the standard toolkits and
SDKs, such as Numpy (ndarray), Win32 (independent device bitmaps), and others, that is, with any
array that uses *steps*