Mat :: clone和Mat :: copyTo有什么区别?

编程入门 行业动态 更新时间:2024-10-24 03:23:25
本文介绍了Mat :: clone和Mat :: copyTo有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

docs.opencv/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.

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

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有什么区别?

本文发布于:2023-11-25 02:44:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628003.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   Mat   clone   copyTo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!