使用OpenCV对两幅图像求和(求混合(blending)

使用OpenCV对两幅图像求和



目的

什么是线性混合,有什么样的用处 使用addWeighted对两幅图像求和

一、C++代码

#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;

static void Blending() {
	double  beta, input , alpha = 0.5;
	Mat src1, src2, dst;
	const string path1("E:/picture/win7.jpg");
	const string path2("E:/picture/linux1.jpg");
	const string input_image("input1 image");
	const string output_image("input2 image");
	const string output_blend("output blend image");

	//Ask the user enter alpha
	cout << "Simple Liner Blender" << endl;
	cout << " ------------------- " << endl;
	cout << "* Enter alpha [0-1]" << endl;
	cin >> input;

	//Read image(same size,same type)
	src1 = imread(path1);
	src2 = imread(path2);

	//We use the alpha provided by the user if it is between 0 and 1
	if (alpha >= 0 && alpha < 1) {
		alpha = input;
	}
	if (!src1.data) {
		cout << "Error loading sr1 image" << endl;
		return;
	}
	if (!src2.data) {
		cout << "Error loading sr2 image" << endl;
		return;
	}

	//create Window
	namedWindow(input_image, WINDOW_AUTOSIZE);
	namedWindow(output_image, WINDOW_AUTOSIZE);
	namedWindow(output_blend, WINDOW_AUTOSIZE);

	beta = (1.0 - alpha);
	addWeighted(src1, alpha, src2, beta, 0.0, dst);
	imshow(input_image, src1);
	imshow(output_image, src2);
	imshow(output_blend, dst);
	waitKey(0);
}

int main()
{
	Blending();
	return 0;
}

二、结果

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值