代表一幅图像。代表权重,取值范围为0~1。代表另一幅图像
对图像的每一个像素进行此操作。得到混合后图像
我的实践:
#include<opencv2\opencv.hpp>
#include<iostream>
#include<math.h>
using namespace cv;
using namespace std;
//线性混合操作
//相关API
int main()
{Mat src1 = imread("E:\\vs2015\\opencvstudy\\3.jpg", 1);if (!src1.data){cout << "could not load image1!" << endl;return -1;}Mat src2 = imread("E:\\vs2015\\opencvstudy\\4.jpg", 1);if (!src2.data){cout << "could not load image2!" << endl;return -1;}imshow("src1", src1);imshow("src2", src2);Mat dst,dst1;double alpha = 0.5;if (src1.rows == src2.rows && src1.cols == src2.cols && src1.type()==src2.type()){addWeighted(src1, alpha, src2, (1 - alpha), 0, dst, -1);//add(src1, src2, dst1,Mat()); 效果不好//multiply(src1, src2, dst1, 1.0);imshow("addWeightImage", dst);imshow("addWeightImage1", dst1);}else{cout << "could not blend images.the size of iamges is not same!!!" << endl;return -1;}waitKey(0);return 0;}