0.3-OpenCvSharp4 图像叠加

0.3-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);            

0.3-OpenCvSharp4 图像叠加_第1张图片

0.3-OpenCvSharp4 图像叠加_第2张图片

你可能感兴趣的:(OpenCvSharp)