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

1.首先给出opencv文档中,对 rowRange和colRange的定义:cv::Mat Class Reference



下面是解释和翻译:

函数原型:Mat cv::Mat::colRange(int startcol, int endcol)  const

功能:为指定的列跨度创建一个矩阵头。

该方法为矩阵的指定列跨度创建一个矩阵头。 类似于Mat :: row和Mat :: col,这是一个O(1)操作
参数:(分别表示我们想取的Mat的第几列到第几列)

startcol:一个包含0的起始索引的列跨度。

endcol:一个除0以外的结束索引的列跨度。

函数原型:Mat cv::Mat::colRange(const Range& r)  const

  功能:这是为了方便起见,它是一个重载的成员函数。 它与上述函数的区别仅在于它接受的参数。

参数:

r:包含开始和结束索引的范围结构。

rowRange与colRange类似,不再解释

2.代码示例:

#include <opencv2/photo/photo.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <vector>
#include <string>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
using namespace cv;


void loadExposureSeq(String, vector<Mat>&);//加载图像

int main()
{
	String path = "D:\\project\\StructuredLight_Project\\StructuredLight\\cam\\cam_01\\";
	vector<Mat> images;
	loadExposureSeq(path, images);

	return 0;
}

void loadExposureSeq(String path, vector<Mat>& images)
{
	ifstream list_file((path + "list.txt").c_str());//文件读操作,存储设备读取到内存中 
	string name;//txt文件中保存的图片名字
	
	while (list_file >> name ) {
		Mat img = imread(path + name);
		images.push_back(img);
		imshow("img", img);
		waitKey(0);
	}

	Mat res(576, 5 * 768, CV_8UC3);
	for (int i = 0; i < 5; i++)
	{
		res.colRange(i * 768, (i + 1) * 768) = images[i] +0;//从mat中提取特定列
	}

	imwrite("a.png", res);
	waitKey(0);

	list_file.close();//关闭文件流
}

这个函数的作用是:加载了5张图片,存放到一个Mat中,效果如下图所示:



  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值