First time here? Check out the FAQ!

Ask Your Question
3

CopyTo() and Clone() functions

asked Feb 19 '13

izzo gravatar image

updated Feb 19 '13

Need description of the following code :

    1   Mat A = imread(argv[1], CV_LOAD_IMAGE_COLOR);
    2   Mat F = A.clone();
    3   Mat G;
    4   A.copyTo(G);

The second line, is the header A is copied to F ?

The forth line, is the header A copied to G or vice versa( G copied to A) ?

Preview: (hide)

3 answers

Sort by » oldest newest most voted
2

answered Feb 19 '13

unxnut gravatar image

Refer to the link to clone and copyTo in the documentation. On line 2, the header A is copied to F and on line 4, A is copied to G.

Preview: (hide)

Comments

Thank you, i get the idea..

izzo gravatar imageizzo (Feb 19 '13)edit
6

answered Feb 19 '13

berak gravatar image
Mat A = imread(argv[1], CV_LOAD_IMAGE_COLOR);

Mat B = A.clone();  // B is a deep copy of A. (has its own copy of the pixels)
Mat C = A;          // C is a shallow copy of A ( rows, cols copied, but shared pixel-pointer )
Mat D; A.copyTo(D); // D is a deep copy of A, like B
Preview: (hide)

Comments

1

Thanks berak, understood :)

izzo gravatar imageizzo (Feb 19 '13)edit

But is there a performance difference between copyTo() and clone() ?

kanirudh gravatar imagekanirudh (Mar 8 '16)edit

So, it means copy() and clone() does the same task?

Scott_777 gravatar imageScott_777 (Apr 9 '0)edit
-1

answered Mar 18 '16

nicolbiden gravatar image

Clone will copy the structure of a data where as Copy will copy the complete structure as well as data. More about....Clone Vs Copy

Biden

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Feb 19 '13

Seen: 215,462 times

Last updated: Feb 19 '13

Related questions