Why ROI not changed

hi everybody
consider the following code:
cv::Mat out (1000,1,CV_64FC1,cv::Scalar::all(10));
cv::Mat out2 (186,186,CV_64FC1,cv::Scalar::all(20));
cv::Mat diag_i = out2.diag(0);
auto rect = cv::Rect(0, 5, 1, 1000);
cv::Mat out_roi = out(rect);
out_roi = diag_i;

why out matrix does not change?
i select ROI from out matrix and change it by out_roi = diag_i

first, your program is throwing exeptions (did you even run it ?)

use cv::Rect(0, 0, 1, 1000); else its out of bounds

you are not changing the roi, but overwrite(reassign) the out_roi Mat header
it has all properies of diag_i now, and forgotten the prev. content

copying pixels to the roi works like this:

Mat src = ...// same size as rect & same type as outimg

(which you cant do in your case, out_roi an diag_i having different sizes)

1 Like