1. 原理

对两张图片使用如下公式可以得到两张图片的混合图片,

其中f0(x),f1(x)分别是图片1和图片2同一位置的像素点。

2. OpenCV中的AddWeight函数

函数和参数说明:
void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst, int dtype=-)
src1 – first input array.
alpha – weight of the first array elements.
src2 – second input array of the same size and channel number as src1.
beta – weight of the second array elements.
dst – output array that has the same size and number of channels as the input arrays.
gamma – scalar added to each sum.
dtype – optional depth of the output array; when both input arrays have the same depth, dtype can be set to -, which will be equivalent to src1.depth().

实现的转换公式为:

3. 实现代码

void Blend(const Mat& Src1,const Mat& Src2,double alpha,Mat& Dst)
{
double beta = 1.0 - alpha;
addWeighted(Src1,alpha,Src2,beta,0.0,Dst);
namedWindow("原图1");
imshow("原图1",Src1);
waitKey();
namedWindow("原图2");
imshow("原图2",Src2);
waitKey();
namedWindow("混合图");
imshow("混合图",Dst);
waitKey();
}

4. 结果

下图为设置alpha为0.5的处理结果:

5. 相关下载

图片下载

6. 结束

最新文章

  1. CLR中的程序集加载
  2. 3D Grid Effect – 使用 CSS3 制作网格动画效果
  3. 解析sql语句中left_join、inner_join中的on与where的区别
  4. 操作系统性能分析与优化V1.0
  5. ubuntu支持shh远程连接记录
  6. 从扩展方法到匿名方法再到LINQ
  7. Mac下关于——你不能拷贝项目“”,因为它的名称太长或包括的字符在目的宗卷上无效。文件的删除
  8. AndroidTestCase测试用法
  9. Yii2 独立操作
  10. 【Netty】ChannelHandler和ChannelPipeline
  11. ResourceBundle读取文件学习
  12. sql多表数据查询
  13. LoadRunner JAVA Vuser接口测试
  14. 一个优秀的 ring buffer 或 cycle buffer 的实现代码
  15. The Little Prince-11/29
  16. 查看 postgresql 数据库编码,以及修改数据库编码
  17. 关于mysql-connector-java(JDBC驱动)的一些坑
  18. Android 8 wifi 扫描时间间隔
  19. [Java学习] Java类的基本运行顺序
  20. Linux时间子系统(一) 基本概念

热门文章

  1. 2018.11.8 Error contacting service. It is probably not running.
  2. IntelliJ IDEA 快速搭建 Spring MVC环境
  3. git报错error: src refspec refs/heads/master does not match any.
  4. Android学习笔记_40_系统结构 目录结构
  5. Android学习笔记_10_ContentProvider内容提供者的使用
  6. 【题解】洛谷P2607【ZJOI2008】骑士
  7. PHP中级面试经历
  8. LeetCode10.正则表达式匹配 JavaScript
  9. BFC、IFC、GFC、FFC
  10. swift计算label动态宽度和高度