创建Mat
#include<opencv2/opencv.hpp>
#include<iostream>
#include<cassert>
#include<vector>
#include<stdio.h>
#include <sys/time.h> using namespace cv;
using namespace std; double abtic()
{
double result = 0.0;
struct timeval tv;
gettimeofday(&tv, NULL);
result = tv.tv_sec** + tv.tv_usec;
return result;
} int main(int argc, char** argv)
{
double time = 0.0;
Mat srcImage=imread(argv[], CV_LOAD_IMAGE_COLOR);
Mat B;
Mat C; B = Mat(srcImage);
printf("B-data address:%p\n", B.data);
printf("srcImage-data address:%p\n", srcImage.data); B.copyTo(C);//deep copy
printf("C-data address:%p\n", C.data); Mat D(B);
printf("D-data address:%p\n", D.data); Mat E;
E = B.clone();//deep copy
printf("E-data address:%p\n", E.data); Mat F = Mat_<uchar>(B);//same Mat(m)
printf("F-data address:%p\n", F.data);
//Mat G = Mat_<int>(B);//datatype is different,cat not work time = abtic();
Mat G;
B.convertTo(G, CV_64FC3);//矩阵元素数据类型的转换
cout << "time(ms):" << (abtic()-time)/ << endl;
printf("G-data address:%p\n", G.data);
cout << "G.channels:" << G.channels() << endl;
cout << G.at<Vec3d>(,)[] << endl;
cout << G.at<Vec3d>(,)[] << endl;
cout << G.at<Vec3d>(,)[] << endl;
cout << "G.size:" << G.total() << endl;
cout << "G.rows:" << G.rows << endl;
cout << "G.cols:" << G.cols << endl; Mat H = Mat_<double>(G);//多通道强转单通道,列数会增加,即高度不变,宽度变为原来的3倍
printf("H-data address:%p\n", H.data);
cout << "H.channels:" << H.channels() << endl;
cout << H.at<double>(,) << endl;
cout << "H.size:" << H.total() << endl;
cout << "H.rows:" << H.rows << endl;
cout << "H.cols:" << H.cols << endl; //result print:
//B-data address:0x7ff653b2c020
//srcImage-data address:0x7ff653b2c020
//C-data address:0x7ff653a6b020
//D-data address:0x7ff653b2c020
//E-data address:0x7ff645b6b020
//F-data address:0x7ff653b2c020
//G-data address:0x7ff64556a020
//H-data address:0x7ff64556a020 return ;
}
Mat::clone
Creates a full copy of the array and the underlying data.
- C++: Mat Mat::clone() const
The method creates a full copy of the array. The original step[] is not taken into account. So, the array copy is a continuous array occupying total()*elemSize() bytes.
inline Mat Mat::clone() const
{
Mat m;
copyTo(m);
return m;
}
Mat::copyTo
Copies the matrix to another one.
- C++: void Mat::copyTo(OutputArray m) const
- C++: void Mat::copyTo(OutputArray m, InputArray mask) const
-
Parameters: - m – Destination matrix. If it does not have a proper size or type before the operation, it is reallocated.
- mask – Operation mask. Its non-zero elements indicate which matrix elements need to be copied.
The method copies the matrix data to another matrix. Before copying the data, the method invokes
m.create(this->size(), this->type());
so that the destination matrix is reallocated if needed. While m.copyTo(m); works flawlessly, the function does not handle the case of a partial overlap between the source and the destination matrices.
When the operation mask is specified, if the Mat::create call shown above reallocates the matrix, the newly allocated matrix is initialized with all zeros before copying the data.
Mat::convertTo
Converts an array to another data type with optional scaling.
- C++: void Mat::convertTo(OutputArray m, int rtype, double alpha=1, double beta=0 ) const
-
Parameters: - m – output matrix; if it does not have a proper size or type before the operation, it is reallocated.
- rtype – desired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input.
- alpha – optional scale factor.
- beta – optional delta added to the scaled values.
The method converts source pixel values to the target data type. saturate_cast<> is applied at the end to avoid possible overflows:
m(x,y)=saturate_case<rType>(a(*this)(x,y)+b)
创建Mat的更多相关文章
- OpenCV——创建Mat对象、格式化输出、常用数据结构和函数(point,vector、Scalar、Size、Rect、cvtColor)
创建Mat对象:
- 创建Mat对象的几种方法
1.Mat的构造函数 Mat M(行数,列数,数据类型,通道数) eg:M(2,2, CV_8UC3, Scalar(0,0,255)). 2.利用Mat的Create()函数.Mat M; M.cr ...
- 创建Mat对象
Mat 是一个非常优秀的图像类,它同时也是一个通用的矩阵类,可以用来创建和操作多维矩阵.有多种方法创建一个 Mat 对象. 1.构造函数方法 下面是一个使用构造函数创建对象的例子. 常用的构造函数 2 ...
- OpenCV——Mat类的创建、复制、函数
Mat类的创建: 方法一: 通过读入一张图像,直接转换为Mat对象 Mat image = imread("test.jpg"); 其中 imread()方法需要传入String类 ...
- OpenCV中Mat的基本用法:创建、复制
OpenCV中Mat的基本用法:创建.复制 一.Mat类的创建: 1.方法一: 通过读入一张图像,直接将其转换成Mat对象. Mat image = imread("test.jpg&quo ...
- OpenCV2:Mat属性type,depth,step
在OpenCV2中Mat类无疑使占据着核心地位的,前段时间初学OpenCV2时对Mat类有了个初步的了解,见OpenCV2:Mat初学.这几天试着用OpenCV2实现了图像缩小的两种算法:基于等间隔采 ...
- OpenCV MAT基本图像容器
参考博客: OpenCv中cv::Mat和IplImage,CvMat之间的转换 Mat - 基本图像容器 Mat类型较CvMat和IplImage有更强的矩阵运算能力,支持常见的矩阵运算(参照Mat ...
- OpenCV(2)-Mat数据结构及访问Mat中像素
Mat数据结构 一开始OpenCV是基于C语言的,在比较早的教材例如<学习OpenCV>中,讲解的存储图像的数据结构还是IplImage,这样需要手动管理内存.现在存储图像的基本数据结构是 ...
- OpenCV中Mat的详解
每次碰到Mat都得反复查具体的用法,网上的基础讲解不多,难得看到一篇,赶快转来收藏~ 原文地址:http://www.opencvchina.com/thread-1039-1-1.html 目标 我 ...
随机推荐
- ubuntu下python3及idle3的安装
一.使用以下命令检查自己的系统下是否有python3 python3 --version 如果出现类似“command not found",则说明你需要安装python3.如果能够出现py ...
- iOS 公司开发者账号申请清单
公司开发者账号申请清单: Apple ID账号申请: (有账号请提供账号密码) Apple ID: (最好是公司邮箱账号) Apple ID密码: (大于8位, 字母或数字组成, 包含 ...
- RxJava 2.x 理解-3
背压:Flowable / Subscriber 在RxJava 1.x 理解 中,没有讲到背压这个概念,是因为学习太落后了,RxJava都出2了,所以直接在2上学. 背压是下游控制上游流速的一种手段 ...
- Eclipse快速补全快捷键Ctrl+1修改为Android Studio的Alt+Enter
步骤: Window ->Preferences->key-> type filter text 下输入quick fix(这个是快速补全的快捷键)改为Alt+Enter 下面的wh ...
- VS2017安装错误:工作负荷不完整,未能安装包“sqlcmdlnutils,version=15.1.61703.130,chip=x64,language=zh-CN”。
场景:已安装的VS2017维护安装MVC4时出现如下错误: 看问题描述是由于sqlcmdlnutils安装失败影响到其它组件的安装,于是单独下载此安装包进行安装,发现安装一切正常,继续维护VS2017 ...
- Ext js 应用例子
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 怎么在VS2010中打开VS2013的项目
其实VS2010与VS2013上的sln文件没有本质的区别.打不开的原因是什么呢?其实原因很简单,两者开头的软件信息不同.因此造成低版本VS的不识别. VS2013版本vs.sln文件开头的软件信息: ...
- CentOS release 6.6 (Final)如何安装firefox和chromium
一.firefox的安装: 1. 安装remi源 rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8 ...
- iOS:CocosPods的装配和配置ReactiveCocoa
关于CocosPods的安装和配置ReactiveCocoa 1. CocoaPods和ReactiveCocoa的安装 CocoaPods是iOS最常用最有名的类库管理工具 使用ReactiveCo ...
- JS中map、forEach、filter、reduce等Array新增方法的区别
数组在各个编程语言中的重要性不言而喻,但是在之前的JavaScript中数组虽然功能已经很强大,但操作方法并不完善,在ECMAScript5中做了适当的补充. Array.isArray(elemen ...