首页 > 其他 > 详细

OpenCV入门:(四:混合两张图片)

时间:2015-12-03 14:10:24      阅读:482      评论:0      收藏:0      [点我收藏+]

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=-1)
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 -1, 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(0);
    namedWindow("原图2");
    imshow("原图2",Src2);    
    waitKey(0);
    namedWindow("混合图");
    imshow("混合图",Dst);
    waitKey(0);
}

4. 结果

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

技术分享

5. 相关下载

图片下载

6. 结束

OpenCV入门:(四:混合两张图片)

原文:http://www.cnblogs.com/Reyzal/p/5015868.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!