1 /**
2 * @file AddingImages.cpp
3 * @brief Simple linear blender ( dst = alpha*src1 + beta*src2 )
4 * @author OpenCV team
5 */
6
7 #include "opencv2/imgcodecs.hpp"
8 #include "opencv2/highgui/highgui.hpp"
9 #include <iostream>
10
11 using namespace cv;
12
13 /**
14 * @function main
15 * @brief Main function
16 */
main(void)17 int main( void )
18 {
19
20 double alpha = 0.5; double beta; double input;
21
22 Mat src1, src2, dst;
23
24 /// Ask the user enter alpha
25 std::cout<<" Simple Linear Blender "<<std::endl;
26 std::cout<<"-----------------------"<<std::endl;
27 std::cout<<"* Enter alpha [0-1]: ";
28 std::cin>>input;
29
30 // We use the alpha provided by the user iff it is between 0 and 1
31 if( alpha >= 0 && alpha <= 1 )
32 { alpha = input; }
33
34 /// Read image ( same size, same type )
35 src1 = imread("../data/LinuxLogo.jpg");
36 src2 = imread("../data/WindowsLogo.jpg");
37
38 if( src1.empty() ) { std::cout<< "Error loading src1"<<std::endl; return -1; }
39 if( src2.empty() ) { std::cout<< "Error loading src2"<<std::endl; return -1; }
40
41 /// Create Windows
42 namedWindow("Linear Blend", 1);
43
44 beta = ( 1.0 - alpha );
45 addWeighted( src1, alpha, src2, beta, 0.0, dst);
46
47 imshow( "Linear Blend", dst );
48
49
50 waitKey(0);
51 return 0;
52 }
53