原理:
原理很简单,就是通过简单的线性操作,使两幅图片或视频产生画面叠化的效果,,通过改变α的值,改变叠化的程度。
用到的函数:
void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, doublegamma, OutputArray dst, int dtype=-1)
|
Parameters: |
|
The function addWeighted calculates the weighted sum of two arrays as follows:
#include
"stdafx.h"
#include <cv.h>
#include <highgui.h>
#include <iostream>
using
namespace cv;
using namespace std;
int
_tmain(int argc, _TCHAR* argv[])
{
double alpha = 0.5;
double beta;
double input;
Mat src1, src2, dst;
//
让用户输入α
cout<<" Simple Linear Blender "<<std::endl;
cout<<"-----------------------"<<std::endl;
cout<<"* Enter alpha [0-1]: ";
cin>>input;
//仅当输入在0和1之内,α才等于输入
if( alpha >= 0 && alpha <= 1 )
{ alpha = input; }
//读入图片
src1 = imread("Lena.jpg");
src2 = imread("Airplane.jpg");
if(
!src1.data ) { printf("Error loading src1 \n"); return -1; }
if( !src2.data ) { printf("Error loading src2 \n"); return -1; }
namedWindow("Linear Blend", 1);
beta
= ( 1.0 - alpha );
addWeighted( src1, alpha, src2, beta, 0.0, dst);
imshow( "Linear Blend", dst );
waitKey(0);
return
0;
}