Adding(blending) two images using OpenCV

#include “opencv2/imgcodecs.hpp”
#include “opencv2/highgui.hpp”
#include
using namespace cv;
// we’re NOT “using namespace std;” here, to avoid collisions between the beta variable and std::beta in c++17
using std::cin;
using std::cout;
using std::endl;

int main(void)
{
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;
input = 0.2;

// We use the alpha provided by the user if it is between 0 and 1
if(input >= 0 && input <= 1)
{
	alpha = input;
}

src1 = imread(samples::findFile("/home/chang/projects/opencv_GPU_example/1.jpg"));
src2 = imread(samples::findFile("/home/chang/projects/opencv_GPU_example/2.jpg"));

if(src1.empty()) { cout << "Error loading src1" << endl; return EXIT_FAILURE;}
if(src2.empty()) { cout << "Error loading src2" << endl; return EXIT_FAILURE;}

beta = (1.0 - alpha);
addWeighted(src1, alpha, src2, beta, 0.0, dst);
imshow("Linear Blend", dst);
waitKey(0);

return 0;

}

发布了43 篇原创文章 · 获赞 0 · 访问量 405

猜你喜欢

转载自blog.csdn.net/weixin_42505877/article/details/103929066