private void button2_Click(object sender, EventArgs e)
{
Image<Bgr, byte> imageSource = new Image<Bgr, byte>((Bitmap)this.pictureBox1.Image);// 原图
Image<Gray, Byte> imageGrayscale = imageSource.Convert<Gray, Byte>();// 灰度化
int thresholdValue = Convert.ToInt32(this.TextboxThreshold.Text); //用于二值化的阀值
Image<Gray, Byte> imageThreshold = imageGrayscale.ThresholdBinary(new Gray(thresholdValue), new Gray(255d)); //对灰度图像二值化
Contour<Point> contour = imageThreshold.FindContours(); // 查找轮廓 得到图像的默认轮廓
//contour = contour.ApproxPoly(double.Parse("2"), 2, new MemStorage()); // 对轮廓进行多边形逼近
int maxLevel = Convert.ToInt32(this.TextBoxDepth.Text); //绘制的轮廓深度
imageSource.Draw(contour, new Bgr(Color.Red), new Bgr(Color.Orange), maxLevel, 1);// 绘制轮廓
MCvBox2D box = CvInvoke.cvMinAreaRect2(contour.Ptr, IntPtr.Zero);
PointF[] points = box.GetVertices();
Point[] ps = new Point[points.Length];
for (int i = 0; i < points.Length; i++)
ps = new Point((int)points.X, (int)points.Y);
imageSource.DrawPolyline(ps, true, new Bgr(Color.Blue), 2);
Image<Gray, Byte> imageDest = null;
imageDest = new Image<Gray, byte>(imageGrayscale.Size);
CvInvoke.cvCanny(imageGrayscale.Ptr, imageDest.Ptr, 100, 150, 3);*/ if (this.pictureBox2.Image != null)
{
this.pictureBox2.Image.Dispose();
this.pictureBox2.Image = null;
}
this.pictureBox2.Image = imageSource.ToBitmap();
}
从原图中抠出每个字的最小正方形矩形, 该怎么做,请高手帮忙解决一下下
|