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 btnOpen_Click(object sender, EventArgs e) { // 加载图像 Mat src = Cv2.ImRead(@"img\openclose.png"); Cv2.ImShow("原图", src); Mat element = new Mat(5, 5, MatType.CV_8U, new Scalar(1)); // 开运算 // 先腐蚀后膨胀。能够排除小亮点。 Mat dest_open = new Mat(); Cv2.MorphologyEx(src, dest_open, MorphTypes.Open, element); Cv2.ImShow("开运算", dest_open); // 闭运算 // 先膨胀后腐蚀。能够排除小黑点。 Mat dest_close = new Mat(); Cv2.MorphologyEx(src, dest_close, MorphTypes.Close, element); Cv2.ImShow("闭运算", dest_close); } } }