参考链接:
https://www.cnblogs.com/phoenixdsg/p/8420716.html
https://blog.csdn.net/qch494562564/article/details/50589253
https://blog.csdn.net/u013270326/article/details/72730812
A.copyTo(B,C)
理解:将C与A取交集,只保留相交(相同)的地方,其余C中没有被交掉的地方都转化为黑色,然后作为最后B的体现
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include<iostream>
using namespace cv;
bool ROI_AddImage()
{
Mat srcImage1 = imread("1.jpg");
Mat logoImage = imread("5.png");
if (!srcImage1.data && !logoImage.data)
{
std::cout << "read filed" << std::endl;
return false;
}
Mat imageROI = srcImage1(Rect(0, 0, logoImage.cols, logoImage.rows));
imshow("imageROI",imageROI);
Mat mask = imread("2.png",0);
logoImage.copyTo(imageROI, mask);
//正解:将mask与logoImage取交集,只保留相交(相同)的地方,其余mask中没有被交掉的地方都转化为黑色,然后作为最后imageROI的体现
//mask和logoImage必须大小相同?
//logoImage.copyTo(imageROI); //没有mask的作用
imshow("imageROI11",imageROI);
imshow("logoImage",logoImage);
namedWindow("srcImage1");
imshow("srcImage1", srcImage1);
}
void main()
{
ROI_AddImage();
waitKey();
}
结果图: