From the OpenCV documentation, it appears that copying a matrix is done using a shallow copy, but when changing one of the copies, a copy is done.
The exact referenc
You can make a deep copy with Mat::copyTo()
. E.g.
Mat a(5,5,CV_32C1),b;
a = 1;
a.copyTo(b);
a = 2;
But no, Mat
does not support copy-on-write. When you need to make a change to a
without affecting b
, you need to make a deep copy of a
to b
, and then modify a
.
It seems you misunderstood. "Before assigning new data, the old data is dereferenced via Mat::release" does not mean that when you write on a
or b
then a copy occurs. It means that when you type b=a
, you lose the data that was in b.
Long story short : copy on write is not supported.