OpenCV学习--Mat::rowRange函数

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 表示第一行。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值