1. 程式人生 > >opencv學習日記之影象融合

opencv學習日記之影象融合

這裡的影象疊加指線性疊加,設影象A的畫素為fA(x),影象B的畫素為fB(x),疊加係數為α,則線性疊加操作為:

α為0-1之間的值,從上面也可以看出,疊加必需保證兩幅輸入影象的尺寸大小相同。

void addWeight(InputArray src1,double alpha,InputArray src2,double beta,double gamma,OutputArray dst,int dtype = -1);
#include"stdafx.h"
#include<iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;
using namespace std;

bool LinearBlending();

int main(void)
{
	// 呼叫
	bool linearblending = LinearBlending();

	cout << linearblending << endl;

	waitKey(0);
	return(0);
}

bool LinearBlending() {
	// 定義區域性變數
	double alphaValue = 0.6;
	double betaValue;
	// 讀取圖片,兩個圖片大小尺寸必須一樣
	Mat src1, src2, dst;
	src1 = imread("E:\\pictures\\For_Project\\New_opencv\\newstar.jpg");
	src2 = imread("E:\\pictures\\For_Project\\New_opencv\\newgo.jpg");
	// 影象混合加權操作
	betaValue = 1.0 - alphaValue;
	addWeighted(src1, alphaValue, src2, betaValue, 0.6, dst);

	namedWindow("原圖1");
	imshow("原圖1", src1);

	namedWindow("原圖2");
	imshow("原圖2", src2);

	namedWindow("效果");
	imshow("效果", dst);

	return true;

}

效果: