#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. [SHOI2009] 交通网络

    简单最短路计数. #include<bits/stdc++.h> #define ll long long using namespace std; #define D double co ...

  2. 【后缀数组】poj3581 Sequence

    考虑第一次切割,必然切割的是翻转后字典序最小的前缀,伪证: 若切割位置更靠前:则会导致第一个数翻转后更靠前,字典序必然更大. 若切割位置更靠后,则显然也会导致字典序更大. ↑,sa即可 对于第二次切割 ...

  3. Exercise02_03

    import java.util.Scanner; public class Mi { public static void main(String[] args){ Scanner input = ...

  4. iOS 调H5方法不执行没反应的坑

    调用H5的方法需要给H5传一些参数,参数中包括图片的base64字符串. 错误一: 图片转base64,后面参数不能随便写,正确做法如下 NSData *imageData = UIImageJPEG ...

  5. oracle--v$lock type字段详解

    Name Description AD ASM Disk AU Lock AF Advisor Framework AG Analytic Workspace Generation AK GES De ...

  6. ctags 小记

    转:http://www.cnblogs.com/napoleon_liu/archive/2011/01/23/1942738.html 简介 ctags − Generate tag files ...

  7. 【java】子类可以通过调用父类的public方法调用父类的private方法,为什么?

    代码1: 打印结果: 代码2: 运行结果: 问题: 代码1中super是父类自己调用自己的add()方法,并在add()方法中调用了私有的del()方法,那为什么打印出来的this是子类? 代码2中t ...

  8. JS中map、forEach、filter、reduce等Array新增方法的区别

    数组在各个编程语言中的重要性不言而喻,但是在之前的JavaScript中数组虽然功能已经很强大,但操作方法并不完善,在ECMAScript5中做了适当的补充. Array.isArray(elemen ...

  9. MyISAM的key_buffer_size和InnoDB的innodb_buffer_pool_size

    一.MyISAM的key_buffer_size MyISAM的索引方式是非聚集索引,主索引和其他索引没有本质区别,在data域都是存储了具体记录行的地址.key_buffer_size规定了系统将多 ...

  10. selenium从入门到应用 - 8,selenium+testNG实现多线程的并发测试

    本系列所有代码 https://github.com/zhangting85/simpleWebtest本文将介绍一个Java+TestNG+Maven+Selenium的web自动化测试脚本环境下s ...