OpenCV实验系列之图片线性混和操作

OpenCV实验系列之基本图片操作

注意:以下内容根据opencv官网提供的教程结合个人理解所得,仅是个人学习笔记,可能存在错误或偏差,欢迎指正。

线性混合的含义

简单说就是把两张图片混合到一起,叠加起来。在官网的教程中给出了以下公式
这里写图片描述
既对两张图片加权相加。

线性混合的实现方法

可以使用遍历像素相加,不过库中提供了以下函数用来混合图片

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

Parameters
src1 first input array.
alpha weight of the first array elements.
src2 second input array of the same size and channel number as src1.
beta weight of the second array elements.
gamma scalar added to each sum.
dst output array that has the same size and number of channels as the input arrays.
dtype optional depth of the output array; when both input arrays have the same depth, dtype can be set to -1, which will be equivalent to src1.depth().

#include<iostream>  
#include <opencv2/core/core.hpp>  
#include <opencv2/highgui/highgui.hpp>  
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

void main()
{
    double alpha = 0.4; double beta; double input;
    Mat src1;
    Mat src2;
    Mat dst;
    src1 = imread( "LinuxLogo.jpg" );
    src2 = imread( "WindowsLogo.jpg" );
    imshow("src1",src1);
    imshow("src2",src2);
    beta = ( 1.0 - alpha );
    addWeighted( src1, alpha, src2, beta, 0.0, dst);
    imshow( "Linear Blend", dst );
    waitKey(0);
}

这里写图片描述
效果图

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值