opencv_圖像的混合操作

#include<opencv2\opencv.hpp>
#include<highgui.h>
#include<iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
   {
	   // read image
	   Mat src = imread("C:/Users/qxq/Pictures/image/1.jpg");

	   if (src.empty())
	   {
		   printf("Could not load image...");
		   return -1;
	   }
		
	
	   Mat src1 = imread("C:/Users/qxq/Pictures/image/fox.jpg");
	   if (src1.empty())
	   {
		   printf("Could not load image src1...");
		   return -1;
	   }
	   //圖像的混合,重疊,含有透明度
	   Mat dst;
	   double alpha = 0.3;
	   //只有兩張圖像尺度相同時纔可以進行混合。(還可以進行加乘操作)
	   if (src.rows == src1.rows &&src.cols == src1.cols &&src.type() == src1.type())
	   {
		   addWeighted(src, alpha, src1, (1 - alpha), 0.0, dst);//含有透明度
		   //multiply(src, src1, dst, 1.0);//2個圖像相乘
		   namedWindow("output", CV_WINDOW_AUTOSIZE);
		   imshow("output", dst);
	   }
	   else
	   {
		   print("could not blend image, the size of images is not same...\n");
	   }
	   namedWindow("input", CV_WINDOW_AUTOSIZE);
	   imshow("input",src);

	   waitKey(0);
	   return 0;
   }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章