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?
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?
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);
no matching function for call to ‘cv::Mat::copyTo(cv::Mat)’ viewtest2.cpp:172:61: note: candidates are: /usr/include/opencv2/core/core.hpp:1651:10: note: void cv::Mat::copyTo(cv::OutputArray) const
in OpenCV 2.4.6. Second solution does work however, but it results into an image with just src. –
Krieger src.copyTo(dst(Rect(left, top, src.cols, src.rows));
3x '(' and 2x ')'? Mat dst_roi = dst(Rect(left, top, src.cols, src.rows);
2x '(' and 1x ')'? Untested code? –
Breaux 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.
© 2022 - 2024 — McMap. All rights reserved.