c#对象检测

时间:2013-01-25 08:08:50

标签: c# image object detection aforge

http://img5.imageshack.us/img5/3315/yenidusuk100003.jpg

如何使用Aforge或任何c#库找到上图中矩形的坐标?

我试过了。但它太慢了。

这些矩形的位置和大小是静态的。

我找到了以下代码。但无法得到任何结果。

Bitmap image = sourceImage; //(Bitmap)Bitmap.FromFile(path);


     BlobCounter blobCounter = new BlobCounter();

     blobCounter.FilterBlobs = true;
     blobCounter.MinHeight = 1;
     blobCounter.MinWidth = 1;

     blobCounter.ProcessImage(image);
     Blob[] blobs = blobCounter.GetObjectsInformation();


     SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

     foreach (var blob in blobs)
     {
         List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blob);
         List<IntPoint> cornerPoints;


         if (shapeChecker.IsQuadrilateral(edgePoints, out cornerPoints))
         {

             if (shapeChecker.CheckPolygonSubType(cornerPoints) == PolygonSubType.Rectangle)
             {

                 List<System.Drawing.Point> Points = new List<System.Drawing.Point>();
                 foreach (var point in cornerPoints)
                 {
                     Points.Add(new System.Drawing.Point(point.X, point.Y));
                 }

                 Graphics g = Graphics.FromImage(image);
                 g.DrawPolygon(new Pen(Color.Red, 5.0f), Points.ToArray());

                 image.Save("result.png");
             }
         }
     }

0 个答案:

没有答案