cv::Mat assignment or copy with guarantee that there is no reallocation
I have code in the form of
cv::Mat function(const cv::Mat&);
cv::Mat a = ..;
cv::Mat b = ..;
cv::Rect roi = ..;
function(b, roi).copyTo(a(roi)); // here
on the line marked with "here" the matrix "a" will be reallocated if dimensions or data type do not match. In my case I only want to change a subregion, so reallocation would be a programming error. As far as I see, a temporary matrix would be created and a would not change at all.
another example:
cv::Mat matrixHeader = someOtherMat(roi)
matrixHeader = a | b; // someOtherMat won't be changed if there is a type mismatch, which is unexpected and without warning
is there a copy method in opencv that throws if the matrices are not compatible?