本文是用ROI实现把一个小logo插入到大图像上。
#include<opencv2/core.hpp>
#include<opencv2/highgui.hpp>
cv::Mat image1,logo;
int main(int argc, char** argv) {
image1 = cv::imread(“E:/3.JPG”);
if (image1.empty()){
printf(“could not load image…\n”);
return -1;
}
cv::namedWindow(“Original Image”);
cv::imshow(“Original Image”, image1);
logo = cv::imread(“E:/6.JPG”);
if (logo.empty()) {
printf(“could not load image…\n”);
return -1;
}
cv::namedWindow(“INPUT Image”);
cv::imshow(“INPUT Image”, logo);
cv::Mat imageROI(image1, //目标图像
cv::Rect(20,20, //ROI坐标
logo.cols,logo.rows)); //ROI大小
logo.copyTo(imageROI,logo);//插入标志图像
cv::namedWindow(“OUTPUT Image”);
cv::imshow(“OUTPUT Image”, image1);
cv::waitKey(0);
return 0;
}