#include <cstdio>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char **argv) {
Mat image1, image2, dst;
// 加载图片
image1 = imread("../../picture/bg1.webp", 1);
image2 = imread("../../picture/bg2.webp", 1);
if (!image1.data and !image2.data) {
printf("No image data \n");
return -1;
}
namedWindow("image1", WINDOW_AUTOSIZE);
imshow("image1", image1);
namedWindow("image2", WINDOW_AUTOSIZE);
imshow("image2", image2);
float alpha = 0.5;
if (image1.rows == image2.rows && image1.cols == image2.cols && image1.type() == image2.type()) {
// 通过权重叠加两幅图
// addWeighted(image1, alpha, image2, 1 - alpha, 0.0, dst);
// 直接叠加两幅图等价于addWeighted(image1, 1, image2, 1, 0.0, dst);
add(image1, image2, dst);
} else {
printf("image1 size is not equal image2 size");
}
namedWindow("contrast image", WINDOW_AUTOSIZE);
imshow("contrast image", dst);
// 等待按键
waitKey(0);
return 0;
}