Copy an cv::Mat inside a ROI of another one

theosem picture theosem · May 7, 2012 · Viewed 86.7k times · Source

I need to copy a cv::Mat image (source) to an ROI of another (Destination) cv::Mat image.

I found this reference, but it seems that it does not work for my case. Do you have any pointers how could I do this using the OpenCV C++ interface?

Answer

Andrey Kamaev picture Andrey Kamaev · May 7, 2012

OpenCV 2.4:

src.copyTo(dst(Rect(left, top, src.cols, src.rows)));

OpenCV 2.x:

Mat dst_roi = dst(Rect(left, top, src.cols, src.rows));
src.copyTo(dst_roi);