原理:         

原理很简单,就是通过简单的线性操作,使两幅图片或视频产生画面叠化的效果,示例程序019--图像求和,通过改变α的值,改变叠化的程度。

 

用到的函数:

void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, doublegamma, OutputArray dst, int dtype=-1)

Parameters:

  • src1 – First source array.
  • alpha – Weight for the first array elements.
  • src2 – Second source array of the same size and channel number as src1 .
  • beta – Weight for the second array elements.
  • dst – Destination array that has the same size and number of channels as the input arrays.
  • gamma – Scalar added to each sum.
  • dtype – Optional depth of the destination array. When both input arrays have the same depth, dtype can be set to -1, which will be equivalent to src1.depth().

The function addWeighted calculates the weighted sum of two arrays as follows:

 

 示例程序019--图像求和

程序代码:

#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;
}

 


运行结果:
示例程序019--图像求和

示例程序019--图像求和

相关文章:

  • 2022-01-26
  • 2022-12-23
  • 2021-07-19
  • 2021-10-10
  • 2021-08-08
  • 2021-07-23
  • 2021-05-29
猜你喜欢
  • 2021-04-29
  • 2021-05-28
  • 2021-10-26
  • 2021-11-06
  • 2021-08-13
  • 2022-12-23
  • 2021-12-02
相关资源
相似解决方案