03-OpenCvSharp4 影像疊加

ch_ccc發表於2020-10-01

03-OpenCvSharp4 影像疊加

影像線性混響:
G = ( 1 − θ ) F + θ ∗ H G=(1-\theta )F+\theta* H G=(1θ)F+θH

權值 θ \theta θ 範圍0-1,F和H是參加疊加的影像,G輸出影像。參與疊加F和H 必須格式大小,型別一樣。
在OpenCV裡面我們使用的API是addWeighted()函式:

//
// 摘要:
//     computes weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma)
//
// 引數:
//   src1:
//
//   alpha:
//
//   src2:
//
//   beta:
//
//   gamma:
//
//   dst:
//
//   dtype:
public static void AddWeighted(InputArray src1, double alpha, InputArray src2, double beta, double gamma, OutputArray dst, int dtype = -1);
 Mat dst = new Mat(srt.Size(),srt.Type());
 double alpha = 0.3;
 Cv2.AddWeighted(srt,alpha,s2,1-alpha,0.0,dst);//疊加
 Cv2.ImShow("原圖",srt);
 Cv2.ImShow("混合",dst);

在這裡插入圖片描述

// 摘要:
//     Computes the per-element sum of two arrays or an array and a scalar.
//	   兩個影像每個畫素相加,存入到輸出影像
// 引數:
//   src1:
//     The first source array
//
//   src2:
//     The second source array. It must have the same size and same type as src1
//
//   dst:
//     The destination array; it will have the same size and same type as src1
//
//   mask:
//     The optional operation mask, 8-bit single channel array; specifies elements of
//     the destination array to be changed. [By default this is null]
//
//   dtype:
public static void Add(InputArray src1, InputArray src2, OutputArray dst, [NullableAttribute(2)] InputArray? mask = null, int dtype = -1);
Mat dst1 = new Mat(srt.Size(),srt.Type());
Cv2.Add(srt,s2,dst1);
Cv2.ImShow("Add",dst1);            

在這裡插入圖片描述

在這裡插入圖片描述

相關文章