项目
代码
using OpenCvSharp;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace OpenCvSharp_Demo
{
public partial class frmMain : Form
{
public frmMain
{
InitializeComponent;
}
string image_path = "";
private void Form1_Load(object sender, EventArgs e)
{
image_path = "1.jpg";
pictureBox1.Image = new Bitmap(image_path);
}
private void button2_Click(object sender, EventArgs e)
{
Mat gray = new Mat(image_path, ImreadModes.Grayscale);
Mat binary = new Mat;
Cv2.AdaptiveThreshold(~gray, binary, 255, AdaptiveThresholdTypes.MeanC, ThresholdTypes.Binary, 15, -2);
Mat kernel = Cv2.GetStructuringElement(MorphShapes.Rect, new OpenCvSharp.Size(4, 4), new OpenCvSharp.Point(-1, -1));
//开运算
Mat dst = new Mat;
Cv2.MorphologyEx(binary, dst, MorphTypes.Open, kernel);
pictureBox2.Image = new Bitmap(dst.ToMemoryStream);
}
}
}
转载此文是出于传递更多信息目的。若来源标注错误或侵犯了您的合法权益,请与本站联系,我们将及时更正、删除、谢谢。
https://www.414w.com/read/420493.html