opencv學習(3)——addWeighted函式將兩幅影象疊加
阿新 • • 發佈:2019-02-05
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include<stdlib.h>
using namespace cv;
/**
* @function main
* @brief Main function
*/
int main( void )
{
double alpha = 0.5; double beta; double input;
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 )
src1 = imread("D:\\software_anz\\opencv\\opencv\\sources\\samples\\data\\LinuxLogo.jpg");
src2 = imread("D:\\software_anz\\opencv\\opencv\\sources\\samples\\data\\WindowsLogo.jpg");
if( src1.empty() ) { std::cout<< "Error loading src1" <<std::endl; return -1; }
if( src2.empty() ) { std::cout<< "Error loading src2"<<std::endl; return -1; }
/// Create Windows
namedWindow("Linear Blend", 1);
beta = ( 1.0 - alpha );
addWeighted( src1, alpha, src2, beta, 0.0, dst);//dst=src1*alpha+src2*beta+gamma;
//void addWeighted(InputArray src1,double alpha,InputArray src2,double beta,double gamma,OutputArray dst,int dtype=-1)
imshow( "Linear Blend", dst );
waitKey(0);
system("pause");
return 0;
}