void add(InputArray src1, InputArray src2, OutputArray dst,InputArray mask=noArray(), int dtype=-1);//dst = src1 + src2
void subtract(InputArray src1, InputArray src2, OutputArray dst,InputArray mask=noArray(), int dtype=-1);//dst = src1 - src2
void multiply(InputArray src1, InputArray src2,OutputArray dst, double scale=1, int dtype=-1);//dst = scale*src1*src2
void divide(InputArray src1, InputArray src2, OutputArray dst,double scale=1, int dtype=-1);//dst = scale*src1/src2
void divide(double scale, InputArray src2,OutputArray dst, int dtype=-1);//dst = scale/src2
void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst);//dst = alpha*src1 + src2
void addWeighted(InputArray src1, double alpha, InputArray src2,double beta, double gamma, OutputArray dst, int dtype=-1);//dst = alpha*src1 + beta*src2 + gamma
void sqrt(InputArray src, OutputArray dst);//计算每个矩阵元素的平方根
void pow(InputArray src, double power, OutputArray dst);//src的power次幂
void exp(InputArray src, OutputArray dst);//dst = e**src(**表示指数的意思)
void log(InputArray src, OutputArray dst);//dst = log(abs(src))
#include
#include
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
Mat src1, src2, dst;
src1 = imread("C:/Users/86180/Desktop/文档/学习/opencv/图片处理/zqy4_1.jpg");
src2 = imread("C:/Users/86180/Desktop/文档/学习/opencv/图片处理/zqy5_1.jpg");
if (!src1.data) {
cout << "could not load image..4." << endl;
return -1;
}
if (!src2.data) {
cout << "could not load image..5." << endl;
return -1;
}
double alpha = 0.5;
if (src1.rows == src2.rows && src1.cols == src2.cols && src1.type() == src2.type())
{
addWeighted(src1, alpha, src2, (1.0 - alpha), 0.0, dst);
imshow("zqy4", src1);
imshow("zqy5", src2);
namedWindow("blend demo", WINDOW_AUTOSIZE);
imshow("blend demo", dst);
}
else
{
cout << "could not blend images, the size of images is not same..." << endl;
return -1;
}
waitKey(0);
return 0;
}
运行结果如下:
原图:
混合之后的图:
如果代码进行一下修改:
double alpha = 0.5;
if (src1.rows == src2.rows && src1.cols == src2.cols && src1.type() == src2.type())
{
//addWeighted(src1, alpha, src2, (1.0 - alpha), 0.0, dst);
add(src1, src2, dst, Mat());//修改的地方在这里(相加)
imshow("zqy4", src1);
imshow("zqy5", src2);
namedWindow("blend demo", WINDOW_AUTOSIZE);
imshow("blend demo", dst);
}
else
{
cout << "could not blend images, the size of images is not same..." << endl;
return -1;
}
double alpha = 0.5;
if (src1.rows == src2.rows && src1.cols == src2.cols && src1.type() == src2.type())
{
//addWeighted(src1, alpha, src2, (1.0 - alpha), 0.0, dst);
//add(src1, src2, dst, Mat());
multiply(src1, src2, dst, 1.0);//修改的地方在这里(相乘)
imshow("zqy4", src1);
imshow("zqy5", src2);
namedWindow("blend demo", WINDOW_AUTOSIZE);
imshow("blend demo", dst);
}
else
{
cout << "could not blend images, the size of images is not same..." << endl;
return -1;
}