OpenCV中Mat类rowRange和colRange的用法

Mat类中的rowRange和colRange 提取某些行或列。

rowRange

为指定的行空间创建矩阵标头。

C++: Mat Mat::rowRange(int startrow, int endrow) 

参数说明:
startrow - 行空间包含基于0的起始索引。
endrow - 一个基于0的行空间结束索引。

colRange

为指定的列范围创建矩阵标头。

C++: Mat Mat::colRange(int startcol, int endcol)

参数说明:
startcol - 列跨度的包含0的开始索引。
endcol - 列跨度的从0开始的独占结束索引。

测试代码

#include <opencv2\opencv.hpp>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
	Mat Test = (Mat_<double>(3, 3) << 0, 1, 2, 3, 4, 5, 6, 7, 8);
	cout << "Total matrix:" << endl;
	cout << Test << endl << endl;

	Mat testrow = Test.rowRange(0, 2).clone();   // 包括左边界,但不包括右边界
	cout << "Row range:" << endl;
	cout << testrow << endl;
	cout << "Test 1 row:" << endl;
	cout << Test.row(0) << endl << endl;

	Mat testcol = Test.colRange(0, 2).clone();   // 包括左边界,但不包括右边界
	cout << "Col range:" << endl;
	cout << testcol << endl;
	return 0;
}

测试结果如下所示:

CSDN图标
  • 9
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值