【发布时间】:2015-11-06 04:49:23
【问题描述】:
` // 处理图像 私人无效ProcessImage(位图位图) { // 锁定图片 BitmapData bitmapData = bitmap.LockBits( 新矩形(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
// step 2 - locating objects
BlobCounter blobCounter = new BlobCounter();
blobCounter.FilterBlobs = true;
blobCounter.MinHeight = 5;
blobCounter.MinWidth = 5;
blobCounter.ObjectsOrder = ObjectsOrder.Size;
blobCounter.ProcessImage(bitmapData);
Blob[] blobs = blobCounter.GetObjectsInformation();
bitmap.UnlockBits(bitmapData);
// step 3 - check objects' type and highlight
SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
Graphics g = Graphics.FromImage(bitmap);
Pen redPen = new Pen(Color.Red, 2); // quadrilateral
for (int i = 0, n = blobs.Length; i < n; i++)
{
List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
List<IntPoint> corners;
// use the shape checker to extract the corner points
if (shapeChecker.IsQuadrilateral(edgePoints,out corners ))
{
// only do things if the corners form a rectangle
if (shapeChecker.CheckPolygonSubType(corners) == PolygonSubType.Rectangle)
{
g.DrawPolygon(redPen, ToPointsArray(corners));
}
}
}
redPen.Dispose();
g.Dispose();
// put new image to clipboard
Clipboard.SetDataObject(bitmap);
// and to picture box
pictureBox1.Image = bitmap;
}
}`In [this link][0] array of rectangles was detected. Now, my question is how do I extract the rectangle from the image. My scenario is I detect the rectangular License plate of a car (colored image converted to binary ) in the image and draw with red the location of the plate.
现在我想从图像中提取以红色绘制的那个盘子。我该怎么做。
由于我的图像是二值图像,我已经应用膨胀来获得正确的 LP 候选者,所有候选者都在图像中被成功识别,但我无法使用 ExtractBiggestBlob 方法提取它们。
请帮忙。提前致谢。
【问题讨论】:
-
提供你已经完成的代码。
-
@Irshad PFA 代码。我想用 g 提取图像中以红色绘制的矩形。绘制多边形方法。附加图像以及示例。提前感谢您的帮助。