opencv实现将2幅图像按照
通过在范围 内改变
,这个操可以用来对两幅图像或两段视频产生时间上的 画面叠化 (cross-dissolve)效果。
#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/legacy/compat.hpp>
#include <cv.h>
#include <iostream>
using namespace std;
using namespace cv;
int main( int argc, char** argv )
{
double alpha = 0.5; double beta; double input;
Mat src1, src2,src3, 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;
input = 0.6;
/// 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(_T("..\\images\\1.jpg"));
src2 = imread(_T("..\\images\\2.jpg"));
if( !src1.data ) { printf("Error loading src1 \n"); return -1; }
if( !src2.data ) { printf("Error loading src2 \n"); return -1; }
Mat rsizeImg(src1.rows,src1.cols,src1.type()); //创建一副和 src1 一样大小的图像
resize(src2,rsizeImg,rsizeImg.size(),0,0,INTER_LINEAR);
imwrite(_T("F:\\MyTest Project\\OpenCV\\images\\3.jpg"),rsizeImg);
/// Create Windows
namedWindow("Linear Blend", 1);
beta = ( 1.0 - alpha );
addWeighted( src1, alpha, rsizeImg, beta, 0.0, dst); //2附图片的大小必须要一样
imshow( "Linear Blend", dst );
waitKey(0);
return 0;
}
结果是: