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

∥☆過路亽.° 提交于 2019-11-26 22:01:48

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);
Mich

In addition or correction to above answers, if you want to copy a smaller region of open Mat to another Mat, you should do:

src(Rect(left,top,width, height)).copyTo(dst);

Did work for me this way:

Mat imgPanel(100, 250, CV_8UC1, Scalar(0));
Mat imgPanelRoi(imgPanel, Rect(0, 0, imgSrc.cols, imgSrc.rows));
imgSrc.copyTo(imgPanelRoi);

imshow("imgPanel", imgPanel);
waitKey();

I am using Opencv 2.4.9 Based on Andrey's answer.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!