Python-OpenCV 图像叠加加权实现
函数说明
cv2.addWeighted(src1, alpha, src2, beta, gamma[, dst[, dtype]]) → dst
- 1
参数说明
- src1 – first input array.
- alpha – weight of the first array elements.
- src2 – second input array of the
same size and channelnumber assrc1. - 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 tosrc1.depth().
此函数可以用一下矩阵表达式来代替:
dst = src1 * alpha + src2 * beta + gamma;
注意:由参数说明可以看出,被叠加的两幅图像必须是尺寸相同、类型相同的;并且,当输出图像array的深度为CV_32S时,这个函数就不适用了,这时候就会内存溢出或者算出的结果压根不对。
CV_32S is a signed 32bit integer value for each pixel
python代码实现:
# coding=utf-8 import cv2 # 底板图案
bottom_pic = 'girl1.jpg'
# 上层图案
top_pic = 'girl2.jpg' bottom = cv2.imread(bottom_pic)
top = cv2.imread(top_pic) h, w, _ = bottom.shape img2 = cv2.resize(top, (w,h), interpolation=cv2.INTER_AREA) #alpha,beta,gamma可调
alpha = 0.7
beta = 1-alpha
gamma = 0 # 权重越大,透明度越低
overlapping = cv2.addWeighted(bottom, alpha, img2, beta, gamma)
#cv2.addWeighted(bottom, 0.5, img2, 0.5, 0)
#overlapping = cv2.addWeighted(bottom,0.8,top,0.2,0)
# 保存叠加后的图片
cv2.imwrite('overlap(8:2).jpg', overlapping) cv2.namedWindow('newImage')
cv2.imshow('newImage',overlapping)
cv2.waitKey()
cv2.destroyAllWindows()
Python-OpenCV 图像叠加加权实现的更多相关文章
- Opencv 图像叠加 添加水印
Opencv 图像叠加 添加水印 C++: void Mat::copyTo(OutputArray m) const C++: void Mat::copyTo(OutputArray m, Inp ...
- Python OpenCV 图像相识度对比
强大的openCV能做什么我就不啰嗦,你能想到的一切图像+视频处理. 这里,我们说说openCV的图像相似度对比, 嗯,说好听一点那叫图像识别,但严格讲, 图像识别是在一个图片中进行类聚处理,比如图片 ...
- 基于Python & Opencv 图像-视频-处理算法
Alg1:图像数据格式之间相互转换.png to .jpg(其他的请举一反三) import cv2 import glob def png2jpg(): images = glob.glob('*. ...
- python+opencv 图像预处理
一 python 生成随机字符串序列+ 写入到图片上 from PIL import Image,ImageDraw,ImageFont import numpy as np import rando ...
- python Opencv图像基础操作
读取并显示图像 如果读取图像首先要导入OpenCV包,方法为: import cv2 读取并显示图像 img = cv2.imread("C:\test1.jpg") OpenCV ...
- Python中图像的缩放 resize()函数的应用
cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) -> dst 参数说明: src - 原图 dst - 目标图像.当参数ds ...
- opencv 3 core组件进阶(2 ROI区域图像叠加&图像混合;分离颜色通道、多通道图像混合;图像对比度,亮度值调整)
ROI区域图像叠加&图像混合 #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp&g ...
- OpenCV学习:实现简单的图像叠加
本实例使用简单的线性叠加方法来实现两幅图像的叠加,主要使用的知识如下: 1)线性融合 2)addWeighted函数 //! computes weighted sum of two arrays ( ...
- [OpenCV] 4、图像叠加 addWeighted
>_<" 这次主要是图像叠加的基本操作: >_<" cv::addWeighted(imageROI, 1.0, logo, 0.6, 0, imageRO ...
随机推荐
- NumPy学习_01 ndarray相关概念
1.NumPy库 NumPy = Numerical Python 是高性能科学计算和数据分析的基础库. pandas库充分借鉴了NumPy的相关概念,先行掌握NumPy库的用法,才能把pandas的 ...
- python3 安装 google-visualization-python(windows10)
google-visualization-python 的 github 官网:https://github.com/google/google-visualization-python 安装: 打开 ...
- list对象中根据两个参数过滤数据
list对象中根据两个参数过滤数据 List<demo> list = new List<demo>() { ,b=,c=,d= }, ,b=,c=,d= }, ,b=,c=, ...
- 让粒子可以在白色背景显示 [Blending Shader 实操]
Unity3D 提供了粒子特效的各种shader,今天要说的是 Additive(因为项目最初就是用了Additive 发生了问题.. ε=ε=ε=┏(゜ロ゜;)┛) Additive Particl ...
- sourceInsight4 完美破解
sourceInsight4 完美破解 参考路径: https://blog.csdn.net/zxy020/article/details/75047670 首先确保你在官网下载了原版4.0并安装好 ...
- 聚类K-Means
import numpy as np x=np.random.randint(0,52,52) x k=3 y=np.zeros(20) y array([ 0., 0., 0., 0., 0., 0 ...
- c# 将object尝试转为指定对象
主方法: /// <summary> /// 将object尝试转为指定对象 /// </summary> /// <param name="data" ...
- MFC选择文件(夹)按钮实现
MFC选择文件(夹)按钮实现 选择文件(夹) void CFileSelectDlg::OnBnClickedButtonSelect() { if(((CButton*)(GetDlgItem(ID ...
- mybatis-plus 3.X 配置
官网配置参数说明地址:https://mp.baomidou.com/config/#logicdeletevalue 本地配置:yml mybatis-plus: mapper-locations: ...
- js之Ajax下载文件
传统上,客户端将依靠浏览器来处理从服务器下载文件.然而,这种方法需要打开一个新的浏览器窗口,iframe或任何其他类型的不友好和黑客行为.为下载请求添加额外的头信息也很困难.更好的解决方案是使用HTM ...