OpenCV学习6--图像混合

理论–线性混合操作
线性混合理论:
这里写图片描述
两幅图像的每个像素都进行加权相加。α的取值范围是0~1。

相关API
线性混合API:
void cv::addWeighted(
inputArray src1,
double alpha,
InputArray src2,
double gamma,
outputArray dst,
int dtype = -1
);

代码演示

#include<iostream>
#include<opencv2/core/core.hpp>
#include<highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>  
#include <math.h>

using namespace cv;
using namespace std;

int main()
{
    Mat src1,src2,dst1,dst2; 
    src1 = imread("1.jpg");
    src2 = imread("2.jpg");
    namedWindow("input1",CV_WINDOW_AUTOSIZE);
    imshow("input1",src1);
    namedWindow("input2",CV_WINDOW_AUTOSIZE);
    imshow("input2",src2);

    double alpha = 0.2;

    if((src1.rows == src2.rows) && (src1.cols == src2.cols) && src1.type() == src2.type())
    {
        addWeighted(src1,alpha,src2,(1-alpha),0.0,dst1);   //加权
        imshow("output1",dst1);
        multiply(src1,src2,dst2,0);
        imshow("output2",dst2);
    }
    else
    {
        cout<<"could not blend picture."<<endl;
    }
    waitKey(0);
    return 0;
}

演示效果:
这里写图片描述

源码和原图片请到Github下载:
https://github.com/MRwangmaomao/OpencvMixPic-Project.git

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

南山二毛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值