zoukankan      html  css  js  c++  java
  • OpenCV入门:(四:混合两张图片)

    1. 原理

    对两张图片使用如下公式可以得到两张图片的混合图片,

    image

    其中f0(x),f1(x)分别是图片1和图片2同一位置的像素点。

    2. OpenCV中的AddWeight函数

    函数和参数说明:
    void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst, int dtype=-1)
    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.
    dst     – output array that has the same size and number of channels as the input arrays.
    gamma     – scalar added to each sum.
    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().

    实现的转换公式为:

    image

    3. 实现代码

    void Blend(const Mat& Src1,const Mat& Src2,double alpha,Mat& Dst)
    {
        double beta = 1.0 - alpha;
        addWeighted(Src1,alpha,Src2,beta,0.0,Dst);
        namedWindow("原图1");
        imshow("原图1",Src1);
        waitKey(0);
        namedWindow("原图2");
        imshow("原图2",Src2);    
        waitKey(0);
        namedWindow("混合图");
        imshow("混合图",Dst);
        waitKey(0);
    }

    4. 结果

    下图为设置alpha为0.5的处理结果:

    image

    5. 相关下载

    图片下载

    6. 结束

  • 相关阅读:
    企业云盘安全性如何 怎样部署
    Sentinel 控制台部署
    nginx代理静态页面添加二级目录
    java socket
    IDEA
    golang代码生成器
    es 单节点问题
    代码模板
    错误摘要 HTTP 错误 403.14
    安装.Net Framework 4.6.2无法安装的2种情况
  • 原文地址:https://www.cnblogs.com/Reyzal/p/5015868.html
Copyright © 2011-2022 走看看