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. 结束

  • 相关阅读:
    RAID技术
    Mysql的用户基本操作
    LNMP之Php的安装配置
    java 实现图片拼接
    java 实现Serv-U FTP 和 SFTP 上传 下载
    Image合并添加文字内容
    AOP切面用于系统日志
    网页评论实现
    java web 实体类生成
    java接口调试思想
  • 原文地址:https://www.cnblogs.com/Reyzal/p/5015868.html
Copyright © 2011-2022 走看看