#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. Codeforces 785E Anton and Permutation(分块)

    [题目链接] http://codeforces.com/contest/785/problem/E [题目大意] 一个1到n顺序排列的数列,每次选择两个位置的数进行交换,求交换后的数列的逆序对数 [ ...

  2. 【DFS序】【线段树】bzoj4034 [HAOI2015]T2

    分开维护树的入栈序和出栈序,用两棵线段树.回答时就是用一颗的减去另一棵的. #include<cstdio> #include<algorithm> using namespa ...

  3. 输入格式MultipleInput

    MultipleInput输入格式允许一个job的输入为多个文件夹下的文件(也就是多路径输入),并且不同文件夹下的文件可以实现不同的map逻辑,不过貌似必须使用相同的reduce逻辑. http:// ...

  4. JavaEE学习路线图

    http://www.cnblogs.com/gaoming7122/archive/2012/11/20/2778308.html

  5. 关于constraint 的disable和enable

    建立主外键的constraint create table emp1(emp_no number(2) constraint emp_emp_no_pk primary key,ename varch ...

  6. postgres访问认证配置文件pg_hba.conf

    pg_hba.conf(默认位于/var/lib/pgsql/10/data/pg_hba.conf)是设置访问认证的主要文件,格式为每条记录一行,每行指定一条访问认证. 设定一条访问认证包含了5个部 ...

  7. stl之list双向链表容器应用基础

    不同于採用线性表顺序存储结构的vector和deque容器.list双向链表中任一位置的元素差值.插入和删除,都具有高效的常数阶算法时间复杂度O(1). 头文件 #include<list> ...

  8. [转载]使用32位64位交叉编码混淆来打败静态和动态分析工具 - wildsator

    0×00 摘要 混淆是一种能增加二进制分析和逆向工程难度与成本的常用技术.主流的混淆技术都是着眼于使用与目标CPU相同的机器代码,在相同的处理器模式下,隐藏代码并进行控制.本文中引入了一种新的混淆方法 ...

  9. virtualbox虚拟机ubuntu操作系统,设置网络互通、访问,能访问虚拟机swoole的http服务

    网络互通 1.设置virtualbox网络连接模式为桥接网卡模式 2.重启虚拟机查看虚拟机IP ifconfig 3.开启window的telnet程序 控制面板->程序->启用或关闭wi ...

  10. rails手脚架(scaffold)功能

    scaffold是一个高速开发rails应用的代码框架.能够使用一条命令实现CRUD操作. 1: 创建一个应用 rails new scaffoldapp cd scaffoldapp rails s ...