Mat :: clone和Mat :: copyTo有什么区别? [英] What's the difference between Mat::clone and Mat::copyTo?

查看:130
本文介绍了Mat :: clone和Mat :: copyTo有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道'copyTo'可以处理遮罩.但是当不需要口罩时,我可以同时使用吗?

I know 'copyTo' can handle mask. But when mask is not needed, can I use both equally?

http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-clone

推荐答案

实际上,即使没有遮罩,它们也是相同.

Actually, they are NOT the same even without mask.

主要区别在于,当目标矩阵和源矩阵具有相同的类型和大小时,copyTo不会更改目标矩阵的地址,而clone始终会为目标矩阵分配新的地址

The major difference is that when the destination matrix and the source matrix have the same type and size, copyTo will not change the address of the destination matrix, while clone will always allocate a new address for the destination matrix.

当在copyToclone之前使用复制分配运算符复制目标矩阵时,这一点很重要.例如,

This is important when the destination matrix is copied using copy assignment operator before copyTo or clone. For example,

使用copyTo:

Mat mat1 = Mat::ones(1, 5, CV_32F);
Mat mat2 = mat1;
Mat mat3 = Mat::zeros(1, 5, CV_32F);
mat3.copyTo(mat1);
cout << mat1 << endl;
cout << mat2 << endl;

输出:

[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]

使用clone:

Mat mat1 = Mat::ones(1, 5, CV_32F);
Mat mat2 = mat1;
Mat mat3 = Mat::zeros(1, 5, CV_32F);
mat1 = mat3.clone();
cout << mat1 << endl;
cout << mat2 << endl;

输出:

[0, 0, 0, 0, 0]
[1, 1, 1, 1, 1]

这篇关于Mat :: clone和Mat :: copyTo有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆