图像叠加和加权叠加
#include "pch.h"
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
bool ROI_AddImage()
{
Mat img1 = imread("F:/timg.jfif");
Mat img2 = imread("F:/timg1.jfif");
if (!img1.data || !img2.data)
{
cout << "jiwawa" << endl;
return false;
}
Mat ROI = img1(Rect(0, 0, img2.cols, img2.rows));
cout << img2.cols << " "<< img2.rows << endl;
//加载掩膜,必须是灰度图
Mat mask = imread("F:/timi1.jfif",0);
//将掩膜复制到ROI
img2.copyTo(ROI, mask);
namedWindow("叠加");
imshow("叠加",img1);
return true;
}
bool LinearBlending()
{
double alpha = 0.5;//值越大,显示的就越明显
double beta = 0.5;
Mat img1, img2, img3;
img1 = imread("F:/g1.jfif");
img2 = imread("F:/g2.jfif");
if (!img1.data || !img2.data)
{
cout << "jiwawa" << endl;
return false;
}
addWeighted(img1, alpha, img2, beta, 0.0, img3);
namedWindow("线性混合加权",1);
imshow("线性混合加权",img3);
return true;
}
int main()
{
//ROI_AddImage();
LinearBlending();
waitKey();
return 0;
}