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

  • 相关阅读:
    USACO 1.3 warmhole
    hadoop本地库与系统版本不一致引起的错误解决方法
    hadoop安装遇到的各种异常及解决办法
    Hadoop学习笔记【分布式文件系统学习笔记】
    Hadoop学习笔记【Hadoop家族成员概述】
    Ext2.x学习笔记
    Memcached学习笔记
    关于反向生成url
    python 练习题- 图书租金计算
    python 练习题- letcode 168. Excel表列名称
  • 原文地址:https://www.cnblogs.com/liusouthern/p/9810659.html
Copyright © 2011-2022 走看看