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图标

版权声明:本文为jpc20144055069原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。