`//处理图像 private void ProcessImage(Bitmap bitmap) { //锁定图像 BitmapData bitmapData = bitmap.LockBits( new Rectangle(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
方法提取它们。
请帮忙。提前致谢。