OpenCV实验系列之基本图片操作
注意:以下内容根据opencv官网提供的教程结合个人理解所得,仅是个人学习笔记,可能存在错误或偏差,欢迎指正。
线性混合的含义
简单说就是把两张图片混合到一起,叠加起来。在官网的教程中给出了以下公式
既对两张图片加权相加。
线性混合的实现方法
可以使用遍历像素相加,不过库中提供了以下函数用来混合图片
void cv::addWeighted ( InputArray src1,
double alpha,
InputArray src2,
double beta,
double gamma,
OutputArray dst,
int dtype = -1
)
Parameters
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.
gamma scalar added to each sum.
dst output array that has the same size and number of channels as the input arrays.
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().
#include<iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void main()
{
double alpha = 0.4; double beta; double input;
Mat src1;
Mat src2;
Mat dst;
src1 = imread( "LinuxLogo.jpg" );
src2 = imread( "WindowsLogo.jpg" );
imshow("src1",src1);
imshow("src2",src2);
beta = ( 1.0 - alpha );
addWeighted( src1, alpha, src2, beta, 0.0, dst);
imshow( "Linear Blend", dst );
waitKey(0);
}
效果图