通过NuGet添加程序包。注意 Windows下选择 OpenCvSharp4.Windows。
OpenCvSharp4.Extensions
using OpenCvSharp; using OpenCvSharp.Extensions; 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; namespace app { public partial class FrmMain : Form { public FrmMain() { InitializeComponent(); } /// <summary> /// 测试 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnTest_Click(object sender, EventArgs e) { //Mat img = new Mat(@"jzh.png", ImreadModes.Color); // 读取图像 Mat img = Cv2.ImRead(@"jzh.png"); // Windows窗体PictureBox加载 picboxDest.Image = BitmapConverter.ToBitmap(img); // 显示图像 Cv2.ImShow("img", img); Mat gray = new Mat(); Cv2.CvtColor(img, gray, ColorConversionCodes.RGB2GRAY); // 转为灰度空间图像 // 显示图像 Cv2.ImShow("blur", gray); // 延时等待按键按下 Cv2.WaitKey(0); } } }