OpenCV静心修炼总结篇5——图像混合

线性混合操作—理论

 

OpenCV api函数

            addWeightted ( 参数1:输入图像1;    参数2:输入图像1的alpha值;

                                       参数3:输入图像2;  参数4:输入图像2的alpha值;

                                      参数4:gamma的值(校验值); 参数6:输出的混合图像;

                                       )

                                     主:两张图片的大小和类型一致。

                                     Saturate(t) :确保t 在0-255之间。

 

 参考代码:

 // 两张同大小类型的图片混合

int image_blend()

{

Mat src1,src2,dst;

src1 = imread("1.png");

src2 =imread("2.png");

if(src1.empty())

{

  printf("不能载入图像1.png\r\n");

  return -1;

}

if(src2.empty())

{

  printf("不能载入图像2.png\r\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-alpha,0.0,dst);

imshow("src1 image",src1);

imshow("src2 image",src2);

imshow("blend image",dst);

}

else

{

    printf("两张图片大大小尺寸不一致\r\n");

}

waitKey(0);

}

猜你喜欢

转载自blog.csdn.net/qq_27762895/article/details/84181300
今日推荐