Constancy of const cv::Mat

asked 2018-10-01 07:34:50 -0600

Jendker gravatar image

updated 2018-10-09 03:12:23 -0600

One of the possibilities of changing the cv::Mat would be to take part of the data with ROI and change their values what in the end would mean, that the values of original cv::Mat were changed. Is it somehow possible that such operation (or any other, which I didn't think about, excluding some dirty tricks with casting) would change the values of the const cv::Mat or can I assume that this will not be allowed and every const Mat is actually constant?

The problem could be that under the hood we are dealing with smart pointers, but maybe this is not an issue, it was somehow taken care of?

EDIT: Maybe to rephrase my question: should I pass input array as read only with cv::InputArray or rather const cv::Mat& ? What would be more desired from the performance and immutability (constancy) point of view?

edit retag flag offensive close merge delete

Comments

1

InputArray implies const.

berak gravatar imageberak ( 2018-10-09 03:18:17 -0600 )edit

Ok, I will stick to InputArray then, thank you!

Jendker gravatar imageJendker ( 2018-10-09 03:21:01 -0600 )edit

And InputArrayOfArrays in case of vector and access with src.getMatVector(vector<mat> output). Just in case someone will be looking at this question in the future.

Jendker gravatar imageJendker ( 2018-10-09 04:54:43 -0600 )edit