How to set ROI in OpenCV?
c, c++, image, opencv
Solution
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);
Problem
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); ```