博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OpenCV学习:实现简单的图像叠加
阅读量:6988 次
发布时间:2019-06-27

本文共 2011 字,大约阅读时间需要 6 分钟。

  本实例使用简单的线性叠加方法来实现两幅图像的叠加,主要使用的知识如下:

  1)线性融合  

   

  2)addWeighted函数

  //! computes weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma)

CV_EXPORTS_W void addWeighted(InputArray src1,                        double alpha,                                   InputArray src2,                        double beta,                                           double gamma,                                OutputArray dst,                              int dtype=-1                                  ); Parameters src1 – First source array. alpha – Weight for the first array elements. src2 – Second source array of the same size and channel number as src1 . beta – Weight for the second array elements. dst – Destination 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 destination array. When both input arrays have the same depth, dtype can be set to -1, which will be equivalent to src1.depth().

  代码如下:

//图像叠加(Mat)  #include 
using namespace cv;using namespace std;int main( int argc, char** argv ){ double alpha = 0.5; double beta; double input; Mat src1, src2, dst; /// 请输入alpha值 cout<<" Simple Linear Blender "<
> input; if( input >= 0.0 && input <= 1.0 ) { alpha = input; } /// 加载相同尺寸,相同格式的两张图像 src1 = imread("./Res/Windows7_logo.jpg"); src2 = imread("./Res/Windows7_text.jpg"); if( !src1.data ) { printf("Error loading src1 \n"); return -1; } if( !src2.data ) { printf("Error loading src2 \n"); return -1; } /// 创建显示窗口 namedWindow("Image one", 1); namedWindow("Image two", 1); namedWindow("Linear Blend", 1); /// 执行线性融合 beta = 1.0 - alpha; addWeighted( src1, alpha, src2, beta, 0.0, dst); /// 显示结果 imshow( "Image one", src1 ); imshow( "Image two", src2 ); imshow( "Linear Blend", dst ); /// 等待键盘事件 waitKey(0); return 0;}

   运行结果:

  

  

转载地址:http://fkzvl.baihongyu.com/

你可能感兴趣的文章
Java Reflection(八):注解
查看>>
经营成功的测试生涯
查看>>
btrace记忆
查看>>
<font color="red">[置顶]</font>
查看>>
Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
查看>>
Spring动态调用
查看>>
Linux字符设备驱动之异步通知
查看>>
八月,整理一些无聊的资料,以便无聊的时候看
查看>>
javaScript:块级作用域学习笔记
查看>>
快来,你想要的koa知识几乎都在这里了!
查看>>
文本分类中的一些小问题
查看>>
wepy 使用中...
查看>>
时序数据异常检测(2)指数平滑方法
查看>>
Redis持久化存储详解(一)
查看>>
AQS同步组件--ReentrantLock与锁
查看>>
Android工程集成flutter
查看>>
人工智慧也能作曲?使用人工智能算法做出来的重金属音乐
查看>>
VUE 执行流程 个人笔记
查看>>
实现简单的正则表达式引擎
查看>>
吴颖二:12.8 午评 1239点位非农夜或会到达的下点位
查看>>