两幅图片相加

,addWeigthed格式,默认dst=a*src1+(1-a)*src2+r,r表示亮度,在程序中一般取0.0。

注意:1、两幅图形必须相同格式,相同大小

            2、src1 = imread("C:/Users/Public/Pictures/Sample Pictures/yujinxiang.jpg",1); C前不能有空格,否则运行不出来

            3、src1 = imread("C:/Users/Public/Pictures/Sample Pictures/yujinxiang.jpg",1);
                  src2 = imread("C:/Users/Public/Pictures/Sample Pictures/qie.jpg",1);

                  1表示彩色图像,可省略不写(要写都写,要不写都不写);若同时为0,则表示灰度图像。

#include "stdafx.h"


#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace cv;
int main( int argc, char** argv )
{
double alpha = 0.5; double beta; double input;
Mat src1, src2, 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;
/// 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("C:/Users/Public/Pictures/Sample Pictures/yujinxiang.jpg",1);
src2 = imread("C:/Users/Public/Pictures/Sample Pictures/qie.jpg",1);
if( !src1.data ) { printf("Error loading src1 \n"); return -1; }
if( !src2.data ) { printf("Error loading src2 \n"); return -1; }
/// Create Windows
namedWindow("Linear Blend", 0);
beta = ( 1.0 - alpha );
//addWeighted produces:dst =alpha src1 +beta src2 + gama,and gama=0.0
addWeighted( src1, alpha, src2, beta, 0.0, dst);
imshow( "Linear Blend", dst );
waitKey(0);
return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值