Creates a matrix header for the specified row span.
-
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.
- 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.
Mat::colRange
Creates a matrix header for the specified column span.
-
C++:
Mat
Mat::
colRange
(int
startcol, int
endcol
)
const
-
C++:
Mat
Mat::
colRange
(const Range&
r
)
const
-
Parameters: - startcol – An inclusive 0-based start index of the column span.
- endcol – An exclusive 0-based ending index of the column span.
- r – Range structure containing both the start and the end indices.
The method makes a new header for the specified column span of the matrix. Similarly to Mat::row() and Mat::col() , this is an O(1) operation.
由于这两个函数返回的是指向原矩阵内部位置的指针,所以最好再利用clone()函数进行数据拷贝创建新的矩阵,代码如下:
结果如下:
Total matrix
[0, -1, 0;
-1, 5, -1;
0, -1, 0]
Row range:
[-1, 5, -1;
0, -1, 0]
Col range:
[-1, 0;
5, -1;
-1, 0]
这两个函数很有趣,它们让我实现不用调用opencv特有函数来实现相应功能,而是自己可以写函数随机应变地实现自己所需的任何图像方面功能。赞一个!