问题描述
我有两张图片,第一个比另一个小.我需要在第一张图像上复制第二张图像.为此,我需要在第一个图像上设置 ROI,将第二个图像复制到第一个图像上,然后重置 ROI.
I have two images, the first one smaller than the other. I need to copy the second image on the first image. To do so, I need to set the ROI on the first one, copy the second image onto the first one and then reset the ROI.
但是我使用的是 C++ 接口,所以我不知道如何做到这一点.在 C 中,我可以使用 cvSetImageROI,但这在 C++ 接口上不起作用.
However I am using the C++ interface so I have no idea how to do this. In C I could have used cvSetImageROI but this doesn't work on the C++ interface.
那么基本上什么是 cvSetImageROI 的 C++ 替代品?
So basically whats the C++ alternative to cvSetImageROI?
//output is a pointer to the mat whom I want the second image (colourMiniBinMask) copied upon
Rect ROI (478, 359, 160, 120);
Mat imageROI (*output, ROI);
colourMiniBinMask.copyTo (imageROI);
imshow ("Gravity", *output);
推荐答案
我认为您有问题.如果第一个比另一个小,并且您想复制第一个图像中的第二个图像,则不需要 ROI.您只需调整第二张图片的大小,将其复制到第一张即可.
I think you have something wrong. If the first one is smaller than the other one and you want to copy the second image in the first one, you don't need an ROI. You can just resize the second image in copy it into the first one.
但是如果你想在第二个中复制第一个,我认为这段代码应该可以工作:
However if you want to copy the first one in the second one, I think this code should work:
cv::Rect roi = cv::Rect((img2.cols - img1.cols)/2,(img2.rows - img1.rows)/2,img1.cols,img1.rows);
cv::Mat roiImg;
roiImg = img2(roi);
img1.copyTo(roiImg);
这篇关于如何在 OpenCV 中设置 ROI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!