using OpenCvSharp; using OpenCvSharp.Extensions; using DlibDotNet; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Threading; namespace app { public partial class FrmMain : Form { public FrmMain() { InitializeComponent(); } /// <summary> /// 滤波 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnBlur_Click(object sender, EventArgs e) { // 加载图像 Mat src = Cv2.ImRead(@"img\jzh.png"); Cv2.ImShow("原图", src); // 方框滤波 Mat box = new Mat(); Cv2.BoxFilter(src, box, -1, new OpenCvSharp.Size(5, 5)); Cv2.ImShow("方框滤波", box); // 均值滤波 Mat blur = new Mat(); Cv2.Blur(src, blur, new OpenCvSharp.Size(5, 5)); Cv2.ImShow("均值滤波", blur); // 高斯滤波 Mat gauss = new Mat(); Cv2.GaussianBlur(src, gauss, new OpenCvSharp.Size(5, 5), 0, 0); Cv2.ImShow("高斯滤波", gauss); // 中值滤波 Mat median = new Mat(); Cv2.MedianBlur(src, median, 5); Cv2.ImShow("中值滤波", median); // 双边滤波 Mat bilater = new Mat(); // d:表示在过滤过程中每个像素邻域的直径范围。如果该值是非正数,则将由sigmaSpace计算。 // sigmaColor:颜色空间过滤器的sigma值,值越大表示有越宽广的颜色混合到一起。 // sigmaSpace:坐标空间中滤波器的sigma值,如果该值较大,则意味着越远的像素将相互影响。 Cv2.BilateralFilter(src, bilater, 25, 25 * 2, (double)BorderTypes.Default); Cv2.ImShow("双边滤波", bilater); } } }