#include<iostream>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
int main(){
Mat back = imread("E:\\AE图片素材\\千反田.jpg",IMREAD_COLOR);
if (!back.data)
{
std::cout << "could not load image...";
return -1;
}
namedWindow("吃蛋挞", WINDOW_NORMAL);
imshow("吃蛋挞", back);
Mat a = imread("E:\\AE图片素材\\AE图标.jpg");
Mat imgROI = back(Rect(50, 50, a.cols, a.rows));
a.copyTo(imgROI);
imshow("after",back);
waitKey(0);
return 0;
}
注意理解:imgROI是一个新定义的Mat,但它是原Mat(这里即back)的“引用”,imgROI的变化会引起原mat的变化。这也是为什么经过了a.copyTo(imgROI);后,执行imshow(“after”,back)时可以看到back发生了变化的原因