#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. Problem Q: 多项式求和x+(x^2)/2!+(x^3)/3!+...

    #include<stdio.h> #include<math.h> int main() { float x,i; scanf("%f",&x); ...

  2. NSNotificationCenter监听TextField文字变化

    注册 1: NSNotificationCenter.defaultCenter().addObserver(self, selector: "textDidChange", na ...

  3. P2P通信标准协议(二)之TURN

    上一篇P2P通信标准协议(一)介绍了在NAT上进行端口绑定的通用规则,应用程序可以根据这个协议来设计网络以外的通信. 但是,STUN/RFC5389协议里能处理的也只有市面上大多数的Cone NAT( ...

  4. 笔记:git基本操作

    原文: http://www.cnblogs.com/pingwen/p/8098035.html 1. 快速入门的基本概念 相比SVN,TFS等集中式的版本管理系统,GIT分布式管理最重要的理念是本 ...

  5. 腾讯云会话服务器node+nginx

    1.除了一个正常的服务器还需要一个会话服务器(websocket),利用node加socket.io来做 2.正常安装Nginx yum install nginx 3.Nginx的配置内容略微不同( ...

  6. [shell 编程] if [ $# -eq 0 ]该语句是什么含义?

    $0: shell或shell脚本的名字$*:以一对双引号给出参数列表$@:将各个参数分别加双引号返回$#:参数的个数$_:代表上一个命令的最后一个参数$$:代表所在命令的PID$!:代表最后执行的后 ...

  7. golangWEB框架gin学习之路由群组

    原文地址:http://www.niu12.com/article/42 package main import ( "github.com/gin-gonic/gin" &quo ...

  8. openstack 动态加载usb,需要修改kvm虚拟机的xml文件

    一.利用libvirt命令动态挂载 在利用KVM的虚拟桌面应用中,有时候需要在虚拟桌面起来后还能够动态的挂载或卸载数据盘,以达到类似热插盘U盘或移动硬盘的效果,当然管理上需要做处理.如果纯粹中技术上来 ...

  9. 算法导论-求x的n次方

    目录 1.分治求x的n次方思路 2.c++代码实现 内容 1.分治求x的n次方思路T(n)=Θ(lgn) 为了计算乘方数a^n,传统的做法(所谓的Naive algorithm)就是循环相乘n次,算法 ...

  10. Implementing DDD Reading - Strategic Design

    1. 概念篇 1.1 领域 广义上讲,领域即是一个组织所做的事情以及其中所包含的一切,也是组织的业务范围以及在其中所进行的活动.软件所讨论的领域即是这个组织的领域,应该是清晰明确的.不同的层面或粒度, ...