Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

What's the point of having a const cv::Mat?

It looks like openCV can modify a Mat even if it's const. Many function (e.g. morphologyExor GaussianBlur) will happily take and modify a const cv::Mat. I suppose that's because they could be making a copy of the header, but then access the raw data and modify it. The OutputArray type is even defined as typedef const _OutputArray& OutputArray;.

Is this by design? What's the idea behind it? How can one protect a cv::Mat from changes?

(a related question is http://answers.opencv.org/question/41212/is-cvmat-copy-constructor-legit/)

What's the point of having a const cv::Mat?

It looks like openCV can modify a Mat even if it's const. Many function (e.g. morphologyExor GaussianBlur) will happily take and modify a const cv::Mat. I suppose that's because they could be making a copy of the header, but then access the raw data and modify it. The OutputArray type is even defined as typedef const _OutputArray& OutputArray;.

Is this by design? What's the idea behind it? How can one protect a cv::Mat from changes?

(a related question is http://answers.opencv.org/question/41212/is-cvmat-copy-constructor-legit/)