Eigentlich sind sie NICHT das gleiche auch ohne Maske.
Der Hauptunterschied besteht darin, dass copyTo
, wenn die Zielmatrix und die Quellmatrix denselben Typ und dieselbe Größe haben, die Adresse der Zielmatrix nicht ändert, während clone
immer eine neue Adresse für die Zielmatrix zuweist.
Dies ist wichtig, wenn die Zielmatrix mit dem Kopierzuweisungsoperator vor copyTo
oder clone
kopiert wird. Zum Beispiel
Mit 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;
Ausgang:
[0, 0, 0, 0, 0]
[0, 0, 0, 0, 0]
Mit 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;
Ausgang:
[0, 0, 0, 0, 0]
[1, 1, 1, 1, 1]
ohne Maske sind beide gleich .. –
Danke. Ich sollte Quellcode nicht nur Dokumente lesen. – yosei