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

  • 相关阅读:
    element-ui 后台问题
    element-ui 使用:rules对表单字段进行验证
    扫码枪 移动端监听
    前端好用工具介绍——wulihub
    移动端 扫描枪输入不弹出键盘
    移动端 input输入实时监听查询数据渲染
    新老系统统一认证解决方案
    转 高性能IO模型浅析
    数据库备份方案
    软件开发阶段数据库升级维护策略
  • 原文地址:https://www.cnblogs.com/liusouthern/p/9810659.html
Copyright © 2011-2022 走看看