opencv::两张图片的线性融合

理论-线性混合操作

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...
");
        return -1;
    }

    waitKey(0);
    return 0;
}
原文地址:https://www.cnblogs.com/osbreak/p/11453017.html