VS2017&OPENCV4.0
混合的两张图片类型和大小必须相同
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
Mat src1, src2, dst, drt;
src1 = imread("D:\\test.jpg");
src2 = imread("D:\\lena.jpg");
if (!src1.data) {
cout << "could not load image test..." << endl;
return -1;
}
if (!src2.data) {
cout << "could not load image lena..." << endl;
return -1;
}
double alpha = 0.5;//设置权衡值
if (src1.rows == src2.rows && src1.cols == src2.cols && src1.type() == src2.type()) {//两幅图像的大小和类型相同
addWeighted(src1, alpha, src2, (1.0 - alpha), 0.0, dst);//相加权衡
multiply(src1, src2, drt, 1.0);//相乘
namedWindow("input1", WINDOW_AUTOSIZE);
namedWindow("input2", WINDOW_AUTOSIZE);
imshow("input1", src1);
imshow("input2", src2);
namedWindow("blend demo1", WINDOW_AUTOSIZE);
imshow("blend demo1", dst);
namedWindow("blend demo2", WINDOW_AUTOSIZE);
imshow("blend demo2", drt);
}
else {
printf("could not blend images , the size of images is not same...\n");
return -1;
}
waitKey(0);
return 0;
}