学习利用加减乘除融合图像,例如加
主要学习addweight函数
#include<opencv2/opencv.hpp>
#include<iostream>
#include<math.h>
using namespace std;
using namespace cv;
int main(int agrc, char **argv)
{
Mat src1,src2,src3,dst;
double a = 1.0, b = 2.0, c = 3.0;
double d = a / c, e = b / c;
printf("%5.2lf %5.2lf\n", d, e);
src1 = imread("D:/test1.jpg");
src2 = imread("D:/test2.jpg");
int height1 = src1.rows;
int wedth1 = src1.cols;
int height2 = src2.rows;
int wedth2 = src2.cols;
printf("%d %d \n %d %d\n", height1, wedth1, height2, wedth2);
resize(src2, src3, Size(),e, d);//2/3代表src3为sr高度c1的1/3,1/3代表src3为src1宽度的2/3
int height3 = src3.rows;
int wedth3 = src3.cols;
printf("%d %d \n %d %d\n", height1, wedth1, height3, wedth3);
if (!src1.data)
{
cout << "could not load src1.." << endl;
return -1;
}
if (!src1.data)
{
cout << "could not load src1.." << endl;
return -1;
}
if (!src3.data)
{
cout << "could not load src3.." << endl;
return -1;
}
double alpha = 0.5;
if ( src1.rows == src3.rows&&src1.cols == src3.cols&&src1.type() == src3.type()) {
addWeighted(src1, alpha, src3, (1.0 - alpha), 0.0, dst);
//add(src1, src3, dst);
//multiply(src1, src3, dst, 1.0);
imshow("src1", src1);
imshow("src3", src3);
namedWindow("blend demo", CV_WINDOW_AUTOSIZE);
imshow("blend demo", dst);
}
else {
printf("could not blend demo,the size is not same");
}
//namedWindow("input", CV_WINDOW_AUTOSIZE);
//imshow("input", src);
waitKey(0);
return 0;
}