Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Deep copy of list of instances with cv::Mat members

What is the best way to make a deep copy of a list of instances who have Mat members?

Lets say I have this class:

class myClass {
        Mat image;

        myClass(Scalar value) {
            this->image =  Mat(300, 300, CV_8UC3, value);

I can populate a list of instances with:


Now I would like a second list that is a deep copy of the instances including the underlying Mat data. Just doing the following does a shallow copy:

list<myClass> newInstances = instances;

The problem is that I have opencv doing some vision stuff in one thread, and I want to copy the data into the main renderer such that the renderer will not keep data from being cleared in the thread.