OpenCV Mat::operator= - does it support copy on write?

后端 未结 2 502
时光取名叫无心
时光取名叫无心 2020-12-19 06:38

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

2条回答
  •  抹茶落季
    2020-12-19 07:00

    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.

提交回复
热议问题