将两张图片混合
P6 图像混合
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
//读取2个图片并展示,如果文件地址不正确,打印相关信息
Mat src1 ,src2 ,autoSrcMix;
src1 = imread("./images/house.tif");
src2 = imread("./images/flower.tif");
if (src1.empty() || src2.empty()) {
cout << "can't find the file " << endl;
return -1;
}
imshow("input image src1", src1);
imshow("input image src2", src2);
//将两张图片自动混合
double alpha = 0.6;
if (src1.rows == src2.rows && src1.cols == src2.cols && src1.type() == src2.type()) {
addWeighted(src1, alpha, src2, (1 - alpha), 0.0, autoSrcMix);
imshow("auto mix picture", autoSrcMix);
}
else {
printf("could not merge the picture");
return -1;
}
waitKey(0);
return 0;
}