I'm trying to paste a smaller image into a larger image, using masks in OpenCV 2.4 via C++.
Without a mask, I copy the small image to the larger image with the following code:
smallImage.copyTo(largeImage(cv::Rect(pt, smallImage.size()));
where pt
has the type of cv::Point2f
. It works perfectly. However, if I apply a mask:
smallImage.copyTo(largeImage(cv::Rect(pt, smallImage.size()), mask);
I get an error from Mat::create
(see documentation):
CV_Assert(!fixedType() || (CV_MAT_CN(type) ==
m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0));
If I remove the cv::Rect
from my code, simplifying it to:
smallImage.copyTo(largeImage, mask);
it works, albeit it doesn't copy to the correct location. How do I solve this?