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

  • 相关阅读:
    构建TensorFlow数据流图
    Python小练习:复制操作
    Python小练习:列表的相关操作
    【Jave】接入极光推送 ------- 封装极光推送工具类
    jenkins邮件-使用变量定制化html邮件报告
    十六进制的颜色转变为rgb,设置透明度,通用方法
    一. Go微服务--隔离设计
    7.23 学习笔记
    7.22 学习笔记
    8.28正睿CSP七连测day1
  • 原文地址:https://www.cnblogs.com/liusouthern/p/9810659.html
Copyright © 2011-2022 走看看