Mat的rowRange和colRange可以获取某些范围内行或列的指针:

Mat::rowRange

Creates a matrix header for the specified row span.

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.
  • 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.

Mat::colRange

Creates a matrix header for the specified column span.

C++:Mat Mat::colRange(int startcol, int endcol)const
C++:Mat Mat::colRange(const Range& r)const
Parameters:
  • startcol – An inclusive 0-based start index of the column span.
  • endcol – An exclusive 0-based ending index of the column span.
  • r – Range structure containing both the start and the end indices.

The method makes a new header for the specified column span of the matrix. Similarly to Mat::row() and Mat::col() , this is an O(1) operation.

由于这两个函数返回的是指向原矩阵内部位置的指针,所以最好再利用clone()函数进行数据拷贝创建新的矩阵,代码如下:

[cpp] view plaincopy
  1. #include <opencv2/core/core.hpp>
  2. #include <opencv2/highgui/highgui.hpp>
  3. #include <iostream>
  4. using namespace cv;
  5. using namespace std;
  6. int main(){
  7. Mat C = (Mat_<double>(3,3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
  8. cout << "Total matrix:" << endl;
  9. cout << C << endl;
  10. Mat row = C.rowRange(1,3).clone();
  11. cout << "Row range:" << endl;
  12. cout << row << endl;
  13. Mat col = C.colRange(1,3).clone();
  14. cout << "Col range:" << endl;
  15. cout << col << endl;
  16. }

结果如下:

Total matrix
[0, -1, 0;
  -1, 5, -1;
  0, -1, 0]
Row range:
[-1, 5, -1;
  0, -1, 0]
Col range:
[-1, 0;
  5, -1;
  -1, 0]

OpenCV从Mat中提取某些行或列相关推荐

  1. opencv如何把一个矩阵不同列分离开_【opencv基础】OpenCV从Mat中提取某些行或列

    前言 Opencv中可以调用函数提取某些连续的行或者列,Mat的rowRange和colRange可以获取某些范围内行或列的指针: 这两个函数返回的是指向原矩阵内部位置的指针,类似于浅拷贝: exam ...

  2. python读取excel部分值存入另一个excel-python3读取excel文件只提取某些行某些列的值方法...

    今天有一位同学给了我一个excel文件,要求读取某些行,某些列,然后我试着做了一个demo,这里分享出来,希望能帮到大家: 首先安装xlrd: pip3 install xlrd 然后上代码: imp ...

  3. 【python学习】批量读取Materials Studio的sdf文件,从文件中提取特定信息并按列存储在CSV文件

    批量读取Materials Studio的sdf文件,从文件中提取特定信息并按列存储在CSV文件 Materials Studio在执行dmol3模块中结构优化任务时,任务结束后会产生一系列的输出文件 ...

  4. python怎么读取excel某一行某一列-python3读取excel文件只提取某些行某些列的值方法...

    今天有一位同学给了我一个excel文件,要求读取某些行,某些列,然后我试着做了一个demo,这里分享出来,希望能帮到大家: 首先安装xlrd: pip3 install xlrd 然后上代码: imp ...

  5. python读取excel某一行内容-python3读取excel文件只提取某些行某些列的值方法

    今天有一位同学给了我一个excel文件,要求读取某些行,某些列,然后我试着做了一个demo,这里分享出来,希望能帮到大家: 首先安装xlrd: pip3 install xlrd 然后上代码: imp ...

  6. python按行读取excel文件_python3读取excel文件只提取某些行某些列的值方法

    今天有一位同学给了我一个excel文件,要求读取某些行,某些列,然后我试着做了一个demo,这里分享出来,希望能帮到大家: 首先安装xlrd: pip3 install xlrd 然后上代码: imp ...

  7. opencv的Mat中step的解释

    网络上对Mat的详解,绝大多数是翻译官方的manual,而官方的manual却恰好对部分(官方认为)我们平时很少使用的内容没有详细的解释,或者对一些实现没有解释细节,因此我们就很难在刚入门时迅速地对某 ...

  8. python创建一个文本文件、包含10行字符串、每行字符串由_Python2:使用正则表达式从文本文件中提取整行,子字符串来自anoth...

    我有个问题.我在Linux系统上使用python2.7.6.在 我要实现的是使用列表中的特定数字,它对应于database文本文件中的最后一个数字,将database文本文件中的整行拉出并打印出来(稍 ...

  9. 游戏得有活动的场景:代码中生成多行多列的LinearLayout布局

    既然是江湖,总得有一些可以到处跑的地儿. 咱是新手,那就排的简单点,排个几行几列的就完事了.至于到底排个几行几列的,这个倒也说不准. 得,那就不能直接在layout/xml里面直接画了.咋办?也好办, ...

最新文章

  1. Android开发之带你轻松集成友盟统计
  2. Unity各个版本的离线文档下载和配置方法
  3. 全球 android手机排行 2013,全球Android手机性能排行 三星Note 3夺魁
  4. 安装 Ffmpeg 步骤
  5. 阮一峰react demo代码研究的学习笔记 - ReactMount.render
  6. oracle 查看任务数量,关于dbms_scheduler创建任务数量的疑问
  7. linux 下 oracle 10.2.0.1 32bit netca报错
  8. 怒江java培训班_怒江万词霸屏是什么意思
  9. mac设置python版本切换,和设置python默认版本
  10. PgSQL · 最佳实践 · 从 MaxCompute (ODPS) 迁移数据到 HybridDB
  11. dnastar拼接反向互补序列_反向互补、反向、互补序列有何区别?
  12. 双网卡电脑同时访问内外网设置静态路由表
  13. 大数据小项目之电视收视率企业项目11
  14. mysql三表关联查询
  15. 基于局部平面拟合的法向估计
  16. mysql数据库备份策略及应用场景
  17. SNAT DNAT
  18. OCX控件的问题以及解决方法
  19. 不狠狠逼一下自己,永远不知道自己有多么强大
  20. 原神服务器维护后抽奖池会更新吗,原神换up池会刷新保底吗

热门文章

  1. python读取大文件csv_对python中大文件的导入与导出方法详解
  2. linux十分钟调度一次,linux系统任务调度命令crontab
  3. E. 2-3-4 Tree
  4. VSCode配置Python开发环境
  5. python自动办公pdf_[Python] 自动化办公 PDF提取文字、表格、图片
  6. php 字符串分割出数字,php 字符串分割函数的总结
  7. python绘制正方形、利用turlr_《像计算机科学家一样思考Python》学习笔记(四)...
  8. 8080端口被占用怎么解决_端口占用不会搞?两行命令就解决!
  9. bat脚本保存dir结果_MySQL备份脚本,应该这么写
  10. Tomcat - Springboot启动的时候初始化的线程池默认配置