opencv学习记录05:图像的线性混合

1、addWeighed函数

g ( x ) = ( 1 − α ) f 0 ( x ) + f 1 ( x ) g(x)=(1-\alpha )f\displaystyle \displaystyle 0(x)+f1(x) g(x)=(1α)f0(x)+f1(x)

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

2、实现代码

#include
#include
#include

using namespace cv;
using namespace std;

int main() {
	Mat src1, src2;

	src1 = imread("F:\\opencv_work\\06图像混合\\Project1\\1.jpg");
	src2 = imread("F:\\opencv_work\\06图像混合\\Project1\\27.jpg");

		if (src1.empty())    
	{
		cout << "can not find image总舵主证件照" << endl;
		return -1;
	}
		if (src2.empty())
		{
			cout << "can not find image2总舵主的日常照片" << endl;
			return -1;
		}	
		namedWindow("总舵主的证件照", WINDOW_FREERATIO);
		imshow("总舵主的证件照", src1);
		namedWindow("总舵主的日常照片", WINDOW_FREERATIO);
		imshow("总舵主的日常照片", src2);

		waitKey(2000);

		//实现部分//
		Mat dst, src3;
		src3 = imread("F:\\opencv_work\\06图像混合\\Project1\\3.jpg");
		if (src3.empty())
		{
			cout << "can not find image" << endl;
		}
		double alpha = 0.5;
		if (src1.rows == src2.rows && src1.cols == src2.cols && src1.type() == src2.type())
		{
			addWeighted(src1, alpha, src2, 1.0 - alpha, 0.0, dst);
			//add(src1, src2,dst, Mat());
			//multiply(src1, src2, dst, 1.0);
			namedWindow("总舵主的混合图像", WINDOW_FREERATIO);
			imshow("总舵主的混合图像", dst);
		}
		else
		{			
			namedWindow("FBI警告", WINDOW_AUTOSIZE);
			imshow("FBI警告", src3);
			//cout << "两张图片的尺寸不相同" << endl;
			waitKey(0);
			/*return 0;*/
		}
			
	waitKey(0);
	return(0);
}

还有一些加、乘操作可以去了解

你可能感兴趣的:(opencv)