opencvC++学习5图像混合

理论:

线性混合操作

公式:

API:

void cvAddWeighted( const CvArr* src1, double alpha,
const CvArr* src2, double beta,

double gamma, CvArr* dst );

src1
第一个原数组. 
alpha 
第一个数组元素的权值 
src2 
第二个原数组 
beta 
第二个数组元素的权值 
dst 
输出数组 
gamma 
添加的常数项。 

函数 cvAddWeighted 计算两数组的加权值的和:

注意点:两张图像的大小和类型必须一致才可以

代码:

#include <opencv2\opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;



int main()
{
	//Mat src;
	Mat src1 = imread("D:/opencv/test1.png");
	if (src1.empty()) {

		printf("imread imgae error");
		return -1;
	}
	Mat src2 = imread("D:/opencv/test2.jpg");
	if (src2.empty()) {

		printf("imread imgae error");
		return -1;
	}
	namedWindow("input1", CV_WINDOW_AUTOSIZE);
	namedWindow("input2", CV_WINDOW_AUTOSIZE);

	imshow("input1", src1);
	imshow("input2", src2);

	Mat dst;
	namedWindow("dst", CV_WINDOW_AUTOSIZE);
	Mat dst2;
	namedWindow("dst2", CV_WINDOW_AUTOSIZE);

	
	double alpha = 0.5;
	if (src1.rows == src2.rows && src1.cols == src2.cols && src1.type() == src2.type()) {

		addWeighted(src1, alpha, src2, 1 - alpha, 0.0, dst);
		imshow("dst", dst);

		add(src1, src2, dst2);
		imshow("dst2", dst2);
	}

	

	waitKey(0);
	return 0;
}

效果:


猜你喜欢

转载自blog.csdn.net/xiansong1005/article/details/80631957