理論-線性混合操作
g(x) 表示 融合圖片中的像素點,f0(x) 和 f1(x) 分別表示背景和前景圖片中的像素點。
//參數1:輸入圖像Mat – src1 //參數2:輸入圖像src1的alpha值 //參數3:輸入圖像Mat – src2 //參數4:輸入圖像src2的alpha值 //參數5:gamma值 //參數6:輸出混合圖像 //注意點:兩張圖像的大小和類型必須一致才可以 void addWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst, int dtype = -1);
int main(int argc, char** argv) { Mat src1, src2, dst; src1 = imread(STRPAHT); src2 = imread(STRPAHT2); if (!src1.data) { cout << "could not load image Linux Logo..." << endl; return -1; } if (!src2.data) { cout << "could not load image WIN7 Logo..." << endl; return -1; } double alpha = 0.5; if (src1.rows == src2.rows && src1.cols == src2.cols && src1.type() == src2.type()) { double alpha = 0.5; addWeighted(src1, (1 - alpha), src2, alpha, 0.0, dst); namedWindow("line-blend", CV_WINDOW_AUTOSIZE); imshow("line-blend", dst); waitKey(0); return 0; } else { printf("could not blend images , the size of images is not same...\n"); return -1; } waitKey(0); return 0; }