C++ 在另一个 ROI 内复制一个 cv::Mat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10481411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy an cv::Mat inside a ROI of another one
提问by theosem
I need to copy a cv::Mat
image (source) to an ROI of another (Destination) cv::Mat
image.
我需要将cv::Mat
图像(源)复制到另一个(目标)cv::Mat
图像的 ROI 。
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?
我找到了这个参考,但它似乎不适用于我的情况。你有什么指示我怎么能用 OpenCV C++ 接口做到这一点?
回答by Andrey Kamaev
OpenCV 2.4:
OpenCV 2.4:
src.copyTo(dst(Rect(left, top, src.cols, src.rows)));
OpenCV 2.x:
OpenCV 2.x:
Mat dst_roi = dst(Rect(left, top, src.cols, src.rows));
src.copyTo(dst_roi);
回答by 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:
除了或更正上述答案之外,如果您想将 open 的较小区域复制Mat
到另一个区域Mat
,您应该这样做:
src(Rect(left,top,width, height)).copyTo(dst);
回答by Renato Aloi
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.
我正在使用 Opencv 2.4.9 基于安德烈的回答。