OpenCV学习:使用OpenCV对两幅图像求和(求混合(blending))
2014-12-30 15:16
363 查看
Opencv_tutorials学习笔记
使用OpenCV对两幅图像求和(求混合(blending))
学习知识点:
线性混合(linear blending)
使用addWeighted进行两幅图像求和
分析说明:
线性混合操作是一种典型的二元像素操作:
通过在范围
内改变
,这个操作可以用来对两幅图像或两段视频产生时间是的画面叠加(cross-dissolve)效果。
代码说明:
addWeighted:计算两个数组的加权和。
参数:
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())
附录:opencv提供的函数实现(自己写的注释,请谨慎参考)
使用OpenCV对两幅图像求和(求混合(blending))
学习知识点:
线性混合(linear blending)
使用addWeighted进行两幅图像求和
分析说明:
线性混合操作是一种典型的二元像素操作:
通过在范围
内改变
,这个操作可以用来对两幅图像或两段视频产生时间是的画面叠加(cross-dissolve)效果。
代码说明:
addWeighted:计算两个数组的加权和。
C: void cvAddWeighted(const CvArr* src1, double alpha, const CvArr* src2, double beta, double gamma, CvArr* dst) C++: void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst, int dtype=-1)
参数:
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())
附录:opencv提供的函数实现(自己写的注释,请谨慎参考)
#include <cv.h> //opencv头文件 #include <highgui.h> #include <iostream> using namespace cv; //使用命名空间 using namespace std; int main( int argc, char** argv ) { double alpha = 0.5; double beta; double input; Mat src1, src2, dst; /// Ask the user enter alpha cout<<" Simple Linear Blender "<<endl; cout<<"-----------------------"<<endl; cout<<"* Enter alpha [0-1]: "; cin>>input; /// We use the alpha provided by the user iff it is between 0 and 1 if( alpha >= 0 && alpha <= 1 ) { alpha = input; } /// Read image ( same size, same type ) src1 = imread("D:\\files\\C_exe\\Img_exercise\\4.jpg"); //读入图像 src2 = imread("D:\\files\\C_exe\\Img_exercise\\9.jpg"); if( !src1.data ) { printf("Error loading src1 \n"); return -1; } //判断图像读取成功与否 if( !src2.data ) { printf("Error loading src2 \n"); return -1; } /// Create Windows namedWindow("Linear Blend", 1); //创建一个显示窗口,Q_yyt:第二个参数为什么是1,不是CV_WINDOW_AUTOSIZE beta = ( 1.0 - alpha ); addWeighted( src1, alpha, src2, beta, 0.0, dst); //调用addWeighted函数 imshow( "Linear Blend", dst ); waitKey(0); return 0; }运行结果:
相关文章推荐
- opencv学习笔记10 使用OpenCV对两幅图像求和(求混合(blending))¶
- 学习OpenCV范例(四)——使用OpenCV对两幅图像求和(求混合(blending))
- opencv c++函数 基础4 使用OpenCV对两幅图像求和(求混合(blending))
- 使用OpenCV对两幅图像求和(求混合(blending))
- OpenCV之core 模块. 核心功能(1)Mat - 基本图像容器 OpenCV如何扫描图像、利用查找表和计时 矩阵的掩码操作 使用OpenCV对两幅图像求和(求混合(blending))
- core核心模块--使用OpenCV对两幅图像求和(求混合(blending))
- 两幅图像求和:求混合(blending)-----学习记录(3)
- OpenCV入门,线性混合 使用addWeight函数将两幅图像叠加
- 使用OpenCV对两幅图像求和
- opencv之图像混合(blending)
- 我的OpenCV学习笔记(18):使用Sobel变化和拉普拉斯变换检测图像边沿
- 【OpenCV学习】计算两幅图像的重叠区域
- 学习opencv之(六)-图像切割,使用ROI
- opencv学习(5) 使用迭代器遍历图像的像素
- Opencv学习笔记(三):图像的使用与操作_颜色空间的变换
- OpenCv学习笔记(四):使用split函数提取彩色图像的三个通道
- OpenCV学习之六: 使用方向梯度直方图估计图像旋转角度
- 学习opencv 使用反向块投影搜寻图像中的物体的位置 cvCalcBackProjectPatch
- 学习opencv 使用反向块投影搜寻图像中的物体的位置 cvCalcBackProjectPatch
- OpenCV学习笔记2:使用opencv进行图像比较