使用OpenCV对两幅图像求和
目的
什么是线性混合,有什么样的用处 使用addWeighted对两幅图像求和
一、C++代码
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
static void Blending() {
double beta, input , alpha = 0.5;
Mat src1, src2, dst;
const string path1("E:/picture/win7.jpg");
const string path2("E:/picture/linux1.jpg");
const string input_image("input1 image");
const string output_image("input2 image");
const string output_blend("output blend image");
cout << "Simple Liner Blender" << endl;
cout << " ------------------- " << endl;
cout << "* Enter alpha [0-1]" << endl;
cin >> input;
src1 = imread(path1);
src2 = imread(path2);
if (alpha >= 0 && alpha < 1) {
alpha = input;
}
if (!src1.data) {
cout << "Error loading sr1 image" << endl;
return;
}
if (!src2.data) {
cout << "Error loading sr2 image" << endl;
return;
}
namedWindow(input_image, WINDOW_AUTOSIZE);
namedWindow(output_image, WINDOW_AUTOSIZE);
namedWindow(output_blend, WINDOW_AUTOSIZE);
beta = (1.0 - alpha);
addWeighted(src1, alpha, src2, beta, 0.0, dst);
imshow(input_image, src1);
imshow(output_image, src2);
imshow(output_blend, dst);
waitKey(0);
}
int main()
{
Blending();
return 0;
}
二、结果