标签:int could 必须 pen not har str clu write
本章主要学习addWeighted(src1,alpha,src2,beta,gamma,dst,dtype=-1)这个函数,参数1:输入图像Mat-src1;
参数2:输入图像Mat-src1的alpha值;
参数3:输入图像Mat-src2;
参数4:输入图像Mat-src2的alpha值(1-alpha);
参数5:gamma值,默认为0;
参数6:输出混合图像
函数功能将两幅图像相加,注意两幅图像类型必须相同,否则相加会出现错误,这个API是opencv自带的,也可以直接用add(src1,src2,dst,Mat()),来操作,效果没有addWeighted
源代码如下:
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat src1, src2, dst;
src1 = imread("C:/Users/Administrator/Desktop/3.jpg");
src2 = imread("C:/Users/Administrator/Desktop/4.jpg");
if (!src1.data)
{
cout << "the image src1 could not load..." << endl;
return -1;
}
if (!src2.data)
{
cout << "the image src2 could not load..." << 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, -1);//图像相加
//add(src1, src2, dst, Mat());
imshow("src1", src1);
imshow("src2", src2);
imshow("blend image", dst);
imwrite("C:/Users/Administrator/Desktop/blend image.jpg", dst);
}
else {
printf("could not blend images,the size of image is not same\n");
return -1;
}
waitKey(0);
return 0;
}
标签:int could 必须 pen not har str clu write
原文地址:http://blog.51cto.com/13485871/2153349