我知道'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有什么区别?
发布评论