学习OpenCV 04 图像混合
线性混合操作
相关API(addWeighted)
void cv::addWeighted(inputArray src1, //参数1:输入图像Mat-src1
double alpha, //参数2:输入图像src1的alpha值
inputArray src2, //参数3:输入图像Mat-src2
double beta, //参数4:输入图像src2的alpha值
double gamma, //参数5:gamma值
outputArray dst, //参数6:输出混合图像
int dtype, //默认值为-1
)
dst(I)=saturate(src1(I)*alpha+src2(I)*beta+gamma); 注意:两张图像的大小和类型必须一致才可以
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main(int argc, char**argv) {
Mat src1, src2, dst;
src1 = imread("D:\\somephotos\\example01.jpg");
src2 = imread("D:\\somephotos\\example02.jpg");
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);
}
else {
printf("src1,src2 aren't the same size or type...\n");
}
imshow("src1", src1);
imshow("src2", src2);
imshow("bend", dst);
waitKey(0);
return 0;
}