zoukankan      html  css  js  c++  java
  • OpenCV 图像叠加or图像混合加权实现

    函数说明

    cv2.addWeighted(src1, alpha, src2, beta, gamma[, dst[, dtype]]) → dst


    参数说明

    • src1 – first input array. 输入的第一个数组
    • alpha – weight of the first array elements. 输入的第一个数组的权重值
    • src2 – second input array of the same size and channelnumber as src1.  输入的第二个数组且尺寸和通道数需要和第一个相同
    • beta – weight of the second array elements.    第二个数组的权重值
    • dst – output array that has the same size and number of channelsas the input arrays.  输入数组(输入的数组的尺寸和通道数和输入的数组应保持一致)
    • gamma – scalar added to each sum.   标量,在按位与计算中将标量加到每个和中,调整整体颜色
    • dtype – optional depth of the output array; when both input arrays have the same depth, dtypecan be set to -1, which will be equivalent to src1.depth().输出数组的可选深度;当两个输入数组具有相同的深度时,dtypecan设置为-1,这将等同于src1.depth()。
    • 此函数可以用一下矩阵表达式来代替:
    dst = src1 * alpha + src2 * beta + gamma;

    话不多说,上代码

    import cv2
    bottom=cv2.imread('bottom.jpg')
    top=cv2.imread('top.jpg')
    #cv2.addWeighted(src1, alpha, src2, beta, gamma[, dst[, dtype]]) → dst
    res = cv2.addWeighted(bottom, 0.7, top, 0.3, 0)   #beta和alpha的和为1
    cv2.namedWindow('。。。')   #创建一个新窗口
    cv2.imshow('',res)   #展示图片
    cv2.waitKey()   #图片保持
    cv2.destroyAllWindows()  #释放窗口
    
    cv2.imwrite('overlap.jpg', res)

    图示

     bottom

     top

     res

  • 相关阅读:
    无废话WPF系列9: Binding的源
    无废话WPF系列7:WPF布局控件
    无废话WPF系列6:各类控件家族详解
    无废话WPF系列13:路由事件
    无废话WPF系列4: x名称空间
    无废话WPF系列12: 依赖属性和附加属性
    用C++设计一个不能被继承的类
    HMM的介绍及实现
    C语言综合实验3—计算器四则运算
    机器学习基础
  • 原文地址:https://www.cnblogs.com/liusouthern/p/9810659.html
Copyright © 2011-2022 走看看