学习opencv 混合两张图片

来源:互联网 发布:南昌大学软件学院录取 编辑:程序博客网 时间:2024/04/28 00:38

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

公式如下:

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 alphacout<<"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 1if (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 windowsnamedWindow("Linear Blend",1);beta = (1.0 - alpha);addWeighted(src1,alpha,src2,beta,0.0,dst);imshow("Linear Blend",dst);waitKey(0);return 0;}

其中用的是opencv自带函数: