opencv/samples/cpp/tutorial_code/ImgProc/AddingImages.cpp

53 lines
1.2 KiB
C++
Raw Normal View History

2011-06-17 23:57:00 +08:00
/**
* @file AddingImages.cpp
* @brief Simple linear blender ( dst = alpha*src1 + beta*src2 )
* @author OpenCV team
*/
2014-07-04 22:48:15 +08:00
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui/highgui.hpp"
2011-06-17 23:57:00 +08:00
#include <iostream>
using namespace cv;
/**
* @function main
2012-10-17 07:18:30 +08:00
* @brief Main function
2011-06-17 23:57:00 +08:00
*/
int main( void )
2011-06-17 23:57:00 +08:00
{
2012-10-17 07:18:30 +08:00
double alpha = 0.5; double beta; double input;
2011-06-17 23:57:00 +08:00
Mat src1, src2, dst;
/// Ask the user enter alpha
std::cout<<" Simple Linear Blender "<<std::endl;
std::cout<<"-----------------------"<<std::endl;
std::cout<<"* Enter alpha [0-1]: ";
std::cin>>input;
// We use the alpha provided by the user iff it is between 0 and 1
if( alpha >= 0 && alpha <= 1 )
{ alpha = input; }
/// Read image ( same size, same type )
2014-09-15 00:16:45 +08:00
src1 = imread("../data/LinuxLogo.jpg");
src2 = imread("../data/WindowsLogo.jpg");
2011-06-17 23:57:00 +08:00
if( src1.empty() ) { std::cout<< "Error loading src1"<<std::endl; return -1; }
if( src2.empty() ) { std::cout<< "Error loading src2"<<std::endl; return -1; }
2011-06-17 23:57:00 +08:00
/// Create Windows
namedWindow("Linear Blend", 1);
beta = ( 1.0 - alpha );
addWeighted( src1, alpha, src2, beta, 0.0, dst);
2012-10-17 07:18:30 +08:00
2011-06-17 23:57:00 +08:00
imshow( "Linear Blend", dst );
waitKey(0);
return 0;
}