温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

图像混合

发布时间:2020-08-03 03:59:04 来源:网络 阅读:479 作者:zgh0816 栏目:编程语言

本章主要学习addWeighted(src1,alpha,src2,beta,gamma,dst,dtype=-1)这个函数,

参数1:输入图像Mat-src1;

参数2:输入图像Mat-src1的alpha值;

参数3:输入图像Mat-src2;

参数4:输入图像Mat-src2的alpha值(1-alpha);

参数5:gamma值,默认为0;

参数6:输出混合图像

函数功能将两幅图像相加,注意两幅图像类型必须相同,否则相加会出现错误,这个API是opencv自带的,也可以直接用add(src1,src2,dst,Mat()),来操作,效果没有addWeighted

源代码如下:

#include <opencv2/opencv.hpp>

#include <iostream>

using namespace cv;

using namespace std;

int main(int argc, char** argv) 

{

Mat src1, src2, dst;

src1 = imread("C:/Users/Administrator/Desktop/3.jpg");

src2 = imread("C:/Users/Administrator/Desktop/4.jpg");

if (!src1.data)

{

cout << "the image src1 could not load..." << endl;

return -1;

}

if (!src2.data)

{

cout << "the image src2 could not load..." << endl;

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, -1);//图像相加

//add(src1, src2, dst, Mat());

imshow("src1", src1);

imshow("src2", src2);

imshow("blend image", dst);

imwrite("C:/Users/Administrator/Desktop/blend image.jpg", dst);

}

else {

printf("could not blend images,the size of image is not same\n");

return -1;

}

waitKey(0);

return 0;

}

图像混合图像混合图像混合

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI