Mat rowRange、colRange

测试 opencv 中 Mat 的 rowRangecolRange :

1- Mat::rowRange(int startrow, int endrow) 为矩阵的指定行区间创建一个矩阵头

  • startrow – An inclusive 0-based start index of the row span.// 从0开始的行间距索引
  • endrow – An exclusive 0-based ending index of the row span.//终止索引

2- Mat::colRange(int startcol, int endcol) 为矩阵的指定列区间创建一个矩阵头

  • startcol – An inclusive 0-based start index of the col span.// 从0开始的列间距索引
  • endcol – An exclusive 0-based ending index of the col span.//终止索引
#include "opencv2/opencv.hpp"
#include"iostream"
using namespace std;
using namespace cv;
int main()
{
	uchar a[16]={1,0,0,0,
	            0,1,0,0,
	            0,0,1,0,
			    0,0,0,1};
	Mat A(4,4,CV_8UC1,a);
	cout<<"A="<<A<<endl;
 
	Mat row12=A.rowRange(1,2);
	Mat row13=A.rowRange(1,3);
 
	Mat col12=A.colRange(1,2);
	Mat col13=A.colRange(1,3);
	cout<<"A.rowRange(1,2)="<<row12<<endl;
	cout<<endl;
	cout<<"A.rowRange(1,3)="<<row13<<endl;
	cout<<endl;
	cout<<"A.colRange(1,2)="<<col12<<endl;
	cout<<endl;
	cout<<"A.colRange(1,3)="<<col13<<endl;
	cout<<endl;
    return 0;
}

输出如下:

A=[  1,   0,   0,   0;
   0,   1,   0,   0;
   0,   0,   1,   0;
   0,   0,   0,   1]
A.rowRange(1,2)=[  0,   1,   0,   0]

A.rowRange(1,3)=[  0,   1,   0,   0;
   0,   0,   1,   0]

A.colRange(1,2)=[  0;
   1;
   0;
   0]

A.colRange(1,3)=[  0,   0;
   1,   0;
   0,   1;
   0,   0]

所以,rowRange(x,y)colRange(x,y) 是左闭右开 [x,y) .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值