Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace a rectangular region of Mat image

I am working with opencv image processing library. I just want to replace rectangular region(smaller than the original image) of my original Mat image with another small image. I couldn't find a direction to do this

Can anybody help me please. Thanks in advance

like image 935
shadee Avatar asked Sep 03 '25 17:09

shadee


1 Answers

Here's a way, not claiming its the best way.

Mat m = ... // your smaller mat
Mat submat= matOrig.submat(new Rect(x,y, m.cols(), m.rows()) );
m.copyTo(submat);

That should work assuming m doesn't go out of bounds inside matOrig. When you get a submat, it is still linked to its source Mat.

like image 179
medloh Avatar answered Sep 07 '25 10:09

medloh