我编写了一个代码来从图像中定位矩形(我可以在图像本身上绘制矩形)。我现在要做的是获取图像上矩形对象的坐标。我正在使用 Rectangle 类来获取矩形信息。有没有办法我可以做到这一点?
这是我使用的代码
private void ProcessBW(Bitmap bitmap)
{
BlobCounter blobCounter = new BlobCounter();
blobCounter.FilterBlobs = true;
//blobCounter.MinHeight = 6;
//blobCounter.MinWidth = 6;
blobCounter.ProcessImage(bitmap);
// create Image Object using rear image byte[]
System.Drawing.Image imageR = (System.Drawing.Image)bitmap;
// Derive BitMap object using Image instance, so that you can avoid the issue
//"a graphics object cannot be created from an image that has an indexed pixel format"
Bitmap img = new Bitmap(new Bitmap(imageR));
Rectangle[] rects = blobCounter.GetObjectsRectangles();
//Graphics object to draw
Pen pen = new Pen(Color.Red, 2);
Graphics g = Graphics.FromImage(img);
foreach (Rectangle rect in rects)
{
g.DrawRectangle(pen, rect);
}
pictureBox1.Image = img;
pen.Dispose();
g.Dispose();
}
谢谢