1 #include <opencv2/opencv.hpp>
2 #include <iostream>
3 using namespace std;
4 using namespace cv;
5 //----------------------融合函数——-------
6 bool ROI_Addimg()
7 {
8 Mat srcImage = imread("3.jpg");
9 Mat logoImage = imread("1.jpg");
10 //检测是否读取到图片数据
11 if (!srcImage.data)
12 {
13 cout<<"no src data"<<endl;
14 }
15 if (!logoImage.data)
16 {
17 cout<<"no logo data"<<endl;
18 }
19 //定义一个Mat类型并指定ROI区域
20 Mat ROIimage = srcImage(Rect(0,0,logoImage.cols,logoImage.rows));
21 //添加权重
22 addWeighted(ROIimage,0.7,logoImage,0.6,0.,ROIimage);
23 namedWindow("..");
24 imshow("..",srcImage);
25 Mat D(srcImage,Rect(10,10,500,500));
26 namedWindow(".");
27 imshow(".",D);
28 Mat F = srcImage(Range(100,500), Range(20,500));
29 namedWindow("1.");
30 imshow("1.",F);
31 imwrite("123.jpg",srcImage);
32 return true;
33 }
1 #include <iostream>
2 #include <opencv2/opencv.hpp>
3 using namespace std;
4 using namespace cv;
5 bool ROI_Addimg();
6 bool ROI_Addimage()
7 {
8 Mat srcImage = imread("1.jpg");
9 Mat logoImage = imread("2.jpg");
10 if (!srcImage.data)
11 {
12 cout<<"false! no creImage"<<endl;
13 return false;
14 }
15 if (!logoImage.data)
16 {
17 cout<<"SB no logoImage"<<endl;
18 return false;
19 }
20 Mat imageROI = srcImage(Rect(200,250,logoImage.cols,logoImage.rows));
21 //加掩模复制到ROI 必须是灰度图像
22 Mat mask = imread("2.jpg",0);
23 logoImage.copyTo(imageROI,mask);
24 //Mat imageROI1;
25 //addWeighted(imageROI,0.7,logoImage,0.3,0.0,imageROI);
26 namedWindow("...");
27 imshow("...",srcImage);
28 waitKey(1);
29 return true;
30 }
31 void main()
32 {
33 if(ROI_Addimage()&&ROI_Addimg())
34 cout<<"good"<<endl;
35 waitKey(0);
36
37 //return ROI_Addimage();
38 }