理论–线性混合操作
线性混合理论:
两幅图像的每个像素都进行加权相加。α的取值范围是0~1。
相关API
线性混合API:
void cv::addWeighted(
inputArray src1,
double alpha,
InputArray src2,
double gamma,
outputArray dst,
int dtype = -1
);
代码演示
#include<iostream>
#include<opencv2/core/core.hpp>
#include<highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <math.h>
using namespace cv;
using namespace std;
int main()
{
Mat src1,src2,dst1,dst2;
src1 = imread("1.jpg");
src2 = imread("2.jpg");
namedWindow("input1",CV_WINDOW_AUTOSIZE);
imshow("input1",src1);
namedWindow("input2",CV_WINDOW_AUTOSIZE);
imshow("input2",src2);
double alpha = 0.2;
if((src1.rows == src2.rows) && (src1.cols == src2.cols) && src1.type() == src2.type())
{
addWeighted(src1,alpha,src2,(1-alpha),0.0,dst1); //加权
imshow("output1",dst1);
multiply(src1,src2,dst2,0);
imshow("output2",dst2);
}
else
{
cout<<"could not blend picture."<<endl;
}
waitKey(0);
return 0;
}
演示效果:
源码和原图片请到Github下载:
https://github.com/MRwangmaomao/OpencvMixPic-Project.git