/*txwtech
2021.3.28OpenCV06 image blending operation addWeighted
theory-linear blending operation
Related API (addWeighted)
theory-linear blending operation
AddWeighted calculates the sum of the weighted values of two arrays
void cvAddWeighted( const CvArr* src1, double alpha,
const CvArr* src2, double beta,
double gamma, CvArr* dst );
src1 The first original array.
alpha The point value of the first array element
src2 The second original array
beta The point value of the second array element,
dst, outputs
the number of array gamma additions.
The function cvAddWeighted calculates the sum of the weighted values of two arrays:
dst(I)=src1(I)*alpha+src2(I)*beta+gamma
All arrays must be the same type and the same size (or ROI size)
*/
/*txwtech
2021.3.28OpenCV06图像混合操作addWeighted
理论-线性混合操作
相关API (addWeighted)
理论-线性混合操作
AddWeighted 计算两数组的加磅值的和
void cvAddWeighted( const CvArr* src1, double alpha,
const CvArr* src2, double beta,
double gamma, CvArr* dst );
src1 第一个原数组.
alpha 第一个数组元素的磅值
src2 第二个原数组
beta 第二个数组元素的磅值
dst 输出数组
gamma 作和合添加的数量。
函数 cvAddWeighted 计算两数组的加磅值的和:
dst(I)=src1(I)*alpha+src2(I)*beta+gamma
所有的数组必须的相同的类型相同的大小(或 ROI 大小)
*/
#include <opencv2\opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char *argv[])
{
Mat src1;
Mat src2;
Mat dst;
src1 = imread("E:/pictures/win7logo1.jpg");
src2 = imread("E:/pictures/win7logo2.jpg");
//if (src.empty())
if(!src1.data)
{
printf("load win7logo1 image failed\n");
return -1;
}
if (!src2.data)
{
printf("load win6logo2 image failed\n");
return -1;
}
double alpha = 0.5;//
if (src1.rows == src2.rows && src1.cols == src2.cols
&& src1.type() == src2.type())
{
addWeighted(src1,alpha,src2,(1.0-alpha),0.0,dst);
//add(src1,src2,dst,Mat());//强行图像叠加,不推荐
//multiply(src1, src2, dst, 1.0);//像素相乘
imshow("win7a",src1);
imshow("win7b",src2);
namedWindow("mixed image", CV_WINDOW_AUTOSIZE);
imshow("mixed image", dst);
}
else
{
printf("mix failed,size or type is not same\n");
}
waitKey(0);
return 0;
}