The linear blend operator for two images:
dst = α⋅src1+β⋅src2+γ
we can use the following interface to support combine two pictures.
CV_EXPORTS_W void addWeighted(InputArray src1, double alpha, InputArray src2,
double beta, double gamma, OutputArray dst, int dtype = -1);
Notice: we need to use the images which have the same size as input sources.
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
Mat image1 = imread( "/Users/weiyang/Desktop/Untitled.png", IMREAD_COLOR );
Mat image2 = imread( "/Users/weiyang/Desktop/fish.png", IMREAD_COLOR );
Mat dest;
if( image1.empty() || image2.empty() )
{
fprintf( stderr, "No image data \n");
return -1;
}
double alpha = 0.5;
addWeighted( image1, alpha, image2, 1 - alpha, 0.0, dest );
namedWindow( "Display Image", WINDOW_AUTOSIZE );
imshow( "Display Image", dest );
waitKey(0);
return 0;
}