The copy constructor of cv::Mat
does not create a deep copy of the image. It just creates a reference to the original Mat
and increases its reference count.
In the following function of the class, the return
statement calls the copy constructor, returning a reference to the original image
, which is the probable cause of heap corruption:
Mat get_image(){ return image; }
You should return a deep copy of the image
as follows, so that the original image
does not get modified accidentally.
Mat get_image(){ return image.clone(); }