adding two images
来源:互联网 发布:html5 答题游戏源码 编辑:程序博客网 时间:2024/06/16 12:52
#include <opencv2/core/core.hpp>#include <opencv2/imgproc/imgproc.hpp>#include <opencv2/highgui/highgui.hpp>#include <iostream>#include <sstream>using namespace std;using namespace cv;/************************************************************************* blending two images with the same size /************************************************************************/ int main(int argc, char* argv[]) { double alpha = 0.5;double beta;double input;// Ask the user enter alphacout << " Simple Linear Blender " << endl;cout << "-----------------------" << endl;cout << "* Enter alpha [0-1]: ";cin >> input;if (input > 0.0 && input < 1.0) {alpha = input;beta = 1 - alpha; }Mat image1 = imread("marais.jpg");Mat image2 = imread("dog.jpg");Mat result;if (image1.data && image2.data) {if (image1.size() == image2.size()) {addWeighted(image1, alpha, image2, beta, 0.0, result);}else {cout << " the size of the two images is not the same!" << endl;return -1;}}else {cout << "the error of loading images!" << endl;return -1;}imshow("Blending image", result);waitKey(0);return 0;}
![](http://img.my.csdn.net/uploads/201211/17/1353165443_3390.jpg)
![](http://img.my.csdn.net/uploads/201211/17/1353165406_8031.jpg)
![](http://img.my.csdn.net/uploads/201211/17/1353165577_5864.JPG)