두 이미지를 가져와서 입력받은 비율로 blend 하여 윈도우 창으로 출력해보는 실습을 진행했습니다.
아주 간단한 실습입니다.
두 이미지를 합칠 때는 addWeighted() 함수를 사용하여 Linear Blending 합니다.
Linear Blending
: g(x) = (1 - alpha) * f1(x) + alpha * f2(x)
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, const char * argv[]) {
double alpha=0.5; double beta; double input;
Mat src1, src2, dst;
cout << " Simple Linear Blender " << endl;
cout << "-----------------------" << endl;
cout << "* Enter alpha [0.0~1.0]: ";
cin >> input;
if (input >= 0 && input <= 1)
alpha = input;
src1 = imread("src1.jpg", IMREAD_COLOR);
src2 = imread("src2.jpg", IMREAD_COLOR);
if(src1.empty()) { cout << "Error loading src1" << endl; return -1; }
if(src2.empty()) { cout << "Error loading src2" << endl; return -1; }
beta = (1.0 - alpha);
addWeighted(src1, alpha, src2, beta, 0.0, dst);
imshow("Linear Blend", dst);
waitKey(0);
return 0;
}