Mat::rowRange函数学习
Mat的rowRange和colRange函数可以获取某些范围内行或列的指针,具体使用方法如下:
Mat::rowRange
为矩阵的指定行区间创建一个矩阵头。
C++: Mat Mat::rowRange(int startrow, int endrow) const
C++: Mat Mat::rowRange(const Range& r) const
Parameters:
- startrow – An inclusive 0-based start index of the row span.// 从0开始的行间距索引
- endrow – An exclusive 0-based ending index of the row span.//终止索引
- r – Range structure containing both the start and the end indices.
The method makes a new header for the specified row span of the matrix. Similarly to Mat::row() and Mat::col() , this is an O(1) operation.
其实最简单的方法就是在程序里测试,这个函数的含义。
这里参考: OpenCV从Mat中提取某些行或列
Mat类中的rowRange和colRange的用法
程序参考的是第一篇博文,但是我修改了所取矩阵行的范围,(0,1)
代码如下:
Mat Test = (Mat_<double>(3,3) << 0,1,2, 3,4,5, 6,7,8);
cout << "Total matrix:" << endl;
cout << Test << endl;
Mat testrow = Test.rowRange(0,1).clone();
cout << "Row range:" << endl;
cout << testrow << endl;
cout << "Test 1 row:" << endl;
cout << Test.row(0) << endl;
Mat testcol = Test.colRange(0,1).clone();
cout << "Col range:" << endl;
cout << testcol << endl;
因此可以看到,该函数包括左边界,但是不包括右边界。
PS:这里的边界指的是下标索引。因为索引为0才表示第一行,而不是索引为1 表示第一行。