十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
本章主要學(xué)習addWeighted(src1,alpha,src2,beta,gamma,dst,dtype=-1)這個函數(shù),
創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站設(shè)計、成都做網(wǎng)站、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)普蘭,10余年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792
參數(shù)1:輸入圖像Mat-src1;
參數(shù)2:輸入圖像Mat-src1的alpha值;
參數(shù)3:輸入圖像Mat-src2;
參數(shù)4:輸入圖像Mat-src2的alpha值(1-alpha);
參數(shù)5:gamma值,默認為0;
參數(shù)6:輸出混合圖像
函數(shù)功能將兩幅圖像相加,注意兩幅圖像類型必須相同,否則相加會出現(xiàn)錯誤,這個API是opencv自帶的,也可以直接用add(src1,src2,dst,Mat()),來操作,效果沒有addWeighted
源代碼如下:
#include
#include
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat src1, src2, dst;
src1 = imread("C:/Users/Administrator/Desktop/3(1).jpg");
src2 = imread("C:/Users/Administrator/Desktop/4(1).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;
}