问题描述
我有两个图象,比其他小的第一个。我需要第二图像复制在第一图像上。要做到这一点,我需要设置在第一个投资回报率,第二图像复制到第一个,然后重置投资回报率。
不过,我现在用的是C ++接口,所以我不知道如何做到这一点。在C我可以使用cvSetImageROI但这并不C ++的接口上工作。
所以基本上什么C ++的替代cvSetImageROI?
//输出是一个指向在抄谁我想要的第二图像垫(colourMiniBinMask)
矩形ROI(478,359,160,120);垫imageROI(*产出,投资回报率);colourMiniBinMask.copyTo(imageROI);imshow(万有引力,*输出);
我觉得你有什么不对。如果第一个比另一个更小,要在第二图像中的第一个副本,您不需要投资回报率。你可以只调整第二个图像复制到的第一个。
不过,如果要复制的第二个第一个,我觉得这$ C $ C应该工作:
CV ::矩形的投资回报率= CV ::矩形((img2.cols - img1.cols)/ 2,(img2.rows - img1.rows)/2,img1.cols ,img1.rows);CV ::垫roiImg;
roiImg = IMG2(ROI);img1.copyTo(roiImg);
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.
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.
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);
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中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!