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

asked 2017-09-12 17:35:00 -0600

Lorenzo Riano gravatar image

updated 2017-09-14 12:04:03 -0600

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/41...)

edit retag flag offensive close merge delete

Comments

just curious, where did you find, that GaussianBlur manipulates the input image ?

berak gravatar imageberak ( 2017-09-14 03:07:10 -0600 )edit
1

GaussianBlur manipulates the OutputArray, which is typedef-ed as const. Basically it doesn't matter if you have a const cv::Mat, opencv will still change it via the raw pointer.

Lorenzo Riano gravatar imageLorenzo Riano ( 2017-09-14 11:53:41 -0600 )edit