#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的更多相关文章

  1. OpenCV——创建Mat对象、格式化输出、常用数据结构和函数(point,vector、Scalar、Size、Rect、cvtColor)

    创建Mat对象:

  2. 创建Mat对象的几种方法

    1.Mat的构造函数 Mat M(行数,列数,数据类型,通道数) eg:M(2,2, CV_8UC3, Scalar(0,0,255)). 2.利用Mat的Create()函数.Mat M; M.cr ...

  3. 创建Mat对象

    Mat 是一个非常优秀的图像类,它同时也是一个通用的矩阵类,可以用来创建和操作多维矩阵.有多种方法创建一个 Mat 对象. 1.构造函数方法 下面是一个使用构造函数创建对象的例子. 常用的构造函数 2 ...

  4. OpenCV——Mat类的创建、复制、函数

    Mat类的创建: 方法一: 通过读入一张图像,直接转换为Mat对象 Mat image = imread("test.jpg"); 其中 imread()方法需要传入String类 ...

  5. OpenCV中Mat的基本用法:创建、复制

    OpenCV中Mat的基本用法:创建.复制 一.Mat类的创建: 1.方法一: 通过读入一张图像,直接将其转换成Mat对象. Mat image = imread("test.jpg&quo ...

  6. OpenCV2:Mat属性type,depth,step

    在OpenCV2中Mat类无疑使占据着核心地位的,前段时间初学OpenCV2时对Mat类有了个初步的了解,见OpenCV2:Mat初学.这几天试着用OpenCV2实现了图像缩小的两种算法:基于等间隔采 ...

  7. OpenCV MAT基本图像容器

    参考博客: OpenCv中cv::Mat和IplImage,CvMat之间的转换 Mat - 基本图像容器 Mat类型较CvMat和IplImage有更强的矩阵运算能力,支持常见的矩阵运算(参照Mat ...

  8. OpenCV(2)-Mat数据结构及访问Mat中像素

    Mat数据结构 一开始OpenCV是基于C语言的,在比较早的教材例如<学习OpenCV>中,讲解的存储图像的数据结构还是IplImage,这样需要手动管理内存.现在存储图像的基本数据结构是 ...

  9. OpenCV中Mat的详解

    每次碰到Mat都得反复查具体的用法,网上的基础讲解不多,难得看到一篇,赶快转来收藏~ 原文地址:http://www.opencvchina.com/thread-1039-1-1.html 目标 我 ...

随机推荐

  1. 关于Hadoop_env.sh中的HADOOP_CLASSPATH

    之前博客里介绍了如何自定义DoubleArrayWritable,并将该类型的value写入SequenceFile文件中,为了能够使用命令查看这个文件中的内容(果然坑都是一步一步给自己挖的)参考了网 ...

  2. Klaus Aschenbrenner--windbg

    http://www.sqlservercentral.com/blogs/aschenbrenner/?page=1

  3. TCP Socket一些东西

    1. 若connect失败该套接字不可再用,必须close当前套接字,重新调用socket. 手册上注明连接失败后, socket的状态是未知的, 所以再次connect, 可能成功, 也可能失败. ...

  4. 如何用css做一个爱心

    摘要:HTML的标签都比较简单,入门非常的迅速,但是CSS是一个需要我们深度挖掘的东西,里面的很多样式属性掌握几个常用的便可以实现很好看的效果,下面我便教大家如何用CSS做一个爱心. 前期预备知识: ...

  5. wpf一些例子

    相关知识点:WPF - Adorner WPF Diagram Designer http://www.codeproject.com/Articles/484616/MVVM-Diagram-Des ...

  6. 11、Pickle序列化

    概念:   常用语法:DUMP:把现在内存中的对象状态装到硬盘文件上 常用语法:LOAD:把磁盘文件中的对象导入到内存中 小练习: 字典中存账号信息,用pickle dump到文件中,并load进行修 ...

  7. shell脚本之检查局域网中在线的ip地址

    [root@docker-node1 ]# cat ping.sh #!/bin/bash . /etc/init.d/functions for var in {1..254}; do ip=192 ...

  8. Ubuntu16.04安装Pytorch

    一.安装 1. 官方github:https://github.com/pytorch/pytorch Install optional dependencies //安装依赖项 On Linux e ...

  9. Python 自用代码(某方标准类网页源代码清洗)

    用于mongodb中“标准”数据的清洗,数据为网页源代码,须从中提取: 标准名称,标准外文名称,标准编号,发布单位,发布日期,状态,实施日期,开本页数,采用关系,中图分类号,中国标准分类号,国际标准分 ...

  10. Jquery获取当前行的数据

    取表格当前行数据js代码: Java代码 $(function() { $(".myclass").each(function(){     var tmp=$(this).chi ...