Ask Your Question
3

CopyTo() and Clone() functions

asked 2013-02-19 08:50:42 -0600

izzo gravatar image

updated 2013-02-19 08:57:56 -0600

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) ?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
2

answered 2013-02-19 09:13:40 -0600

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.

edit flag offensive delete link more

Comments

Thank you, i get the idea..

izzo gravatar imageizzo ( 2013-02-19 10:04:57 -0600 )edit
6

answered 2013-02-19 09:13:08 -0600

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
edit flag offensive delete link more

Comments

1

Thanks berak, understood :)

izzo gravatar imageizzo ( 2013-02-19 10:02:19 -0600 )edit

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

kanirudh gravatar imagekanirudh ( 2016-03-08 00:46:31 -0600 )edit

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

Scott_777 gravatar imageScott_777 ( 2020-04-09 02:04:53 -0600 )edit
-1

answered 2016-03-18 03:01:47 -0600

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-02-19 08:50:42 -0600

Seen: 214,012 times

Last updated: Feb 19 '13

Related questions