OpenCV从Mat中提取某些行或列
来源:互联网 发布:淘宝网上怎么卖东西 编辑:程序博客网 时间:2024/06/10 17:26
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()函数进行数据拷贝创建新的矩阵,代码如下:
- #include <opencv2/core/core.hpp>
- #include <opencv2/highgui/highgui.hpp>
- #include <iostream>
- using namespace cv;
- using namespace std;
- int main(){
- Mat C = (Mat_<double>(3,3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
- cout << "Total matrix:" << endl;
- cout << C << endl;
- Mat row = C.rowRange(1,3).clone();
- cout << "Row range:" << endl;
- cout << row << endl;
- Mat col = C.colRange(1,3).clone();
- cout << "Col range:" << endl;
- cout << col << endl;
- }
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]
0 0
- OpenCV从Mat中提取某些行或列
- OpenCV从Mat中提取某些行或列
- OpenCV从Mat中提取某些行或列
- Mat类中的rowRange和colRange 提取某些行或列
- 【编程开发】opencv实现对Mat中某一列或某一行的元素进行normalization
- 从RealSense中提取完整的深度和彩色图像,并存在opencv中的Mat里
- OpenCV中Mat的列向量归一化
- OpenCV中CvMat或Mat的类型
- Opencv中Mat图的长、宽、行、列以及图像像素
- opencv中Mat类型操作或转换代码分析
- opencv删除mat矩阵的多行或者多列
- Opencv 中Mat相关
- OpenCV中Mat赋值
- opencv中Mat使用
- OpenCV中Mat数据结构
- opencv中Mat介绍
- opencv中Mat使用
- OpenCV中Mat详解
- jquery加载页面的方法(页面加载完成就执行)
- Swift开发Sprite Kit游戏实践(一)
- 肇州车牌号车辆车主信息查询
- 9.1 手势识别
- 混淆打包及出错信息的解决办法
- OpenCV从Mat中提取某些行或列
- iOS7应用开发入门经典(第5版)读书笔记
- Extjs MVC开发模式
- 订单评价参考
- 正整数加减乘除四则混合运算求值方法 java实现
- JSON相关的,数据彼此间的转化进行了简单地封装,源码如下,支持arc与非arc
- 黑马程序员——————深入理解C/C++函数指针
- android 程序中res/values-v14/styles.xml报错的解决办法
- 有趣的Autolayout示例-Masonry实现