学习opencv 混合两张图片

学习了opencv简单的 图像混合,以下为公开的源码,效果图是自选的0.5混合

公式如下:

using namespace cv;
using namespace std;
int main( int argc, char** argv)
{
	double alpha = 0.5; double beta; double input;
	Mat src1,src2,dst;

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

	//we use the alpha provided by the user if it is between 0 and 1
	if (alpha>=0&&alpha<=1)
	{
		alpha=input;
	}
	//read image ( same size, same type)
	src1 = imread("1.JPG");
	src2 = imread("2.JPG");

	imshow("a",src1);
	if (!src1.data)
	{
		printf("Error looading src1\n");
		return -1;
	}
	if (!src2.data)
	{
		printf("Error looading src2\n");
		return -1;
	}

	//create windows
	namedWindow("Linear Blend",1);

	beta = (1.0 - alpha);

	addWeighted(src1,alpha,src2,beta,0.0,dst);

	imshow("Linear Blend",dst);

	waitKey(0);
	return 0;


}

其中用的是opencv自带函数:





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值