学习opencv 混合两张图片

时间:2023-02-10 19:35:24

学习了opencv简单的 图像混合,以下为公开的源码,效果图是自选的0.5混合

公式如下:

学习opencv 混合两张图片

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]: "<<endl;
cin>>input;

//we use the alpha provided by the user if it is between 0 and 1
if (alpha>=0&&alpha<=1)
{
alpha=input;
}
//read image ( same size, same type)
src1 = imread("1.JPG");
src2 = imread("2.JPG");

imshow("a",src1);
if (!src1.data)
{
printf("Error looading src1\n");
return -1;
}
if (!src2.data)
{
printf("Error looading src2\n");
return -1;
}

//create windows
namedWindow("Linear Blend",1);

beta = (1.0 - alpha);

addWeighted(src1,alpha,src2,beta,0.0,dst);

imshow("Linear Blend",dst);

waitKey(0);
return 0;


}

其中用的是opencv自带函数:

学习opencv 混合两张图片

学习opencv 混合两张图片

学习opencv 混合两张图片