Search code examples
c#image-processingwindows-phone-8.1aforgeaccord.net

How to draw a circle after a circle is detected using SimpleShapeChecker? (Accord.net Portable)


So, I am trying to draw a circle after I found a circle using the SimpleShapeChecker() from the Accord.net portable library using this code:

// locate objects using blob counter
BlobCounter blobCounter = new BlobCounter( );
blobCounter.ProcessImage( bitmap );
Blob[] blobs = blobCounter.GetObjectsInformation( );
// create Graphics object to draw on the image and a pen
Graphics g = Graphics.FromImage( bitmap );
Pen redPen = new Pen( Color.Red, 2 );
// check each object and draw circle around objects, which
// are recognized as circles
for ( int i = 0, n = blobs.Length; i < n; i++ )
{
     List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints( blobs[i] );

     Point center;
     float radius;

     if ( shapeChecker.IsCircle( edgePoints, out center, out radius ) )
          {
          g.DrawEllipse( redPen,
               (int) ( center.X - radius ),
               (int) ( center.Y - radius ),
               (int) ( radius * 2 ),
               (int) ( radius * 2 ) );
          }
}

redPen.Dispose( );
g.Dispose( );

However, both the System.Drawing.Graphics and System.Drawing.Pen shows an error:

"inaccessible due to its protection level"

Therefore I can't really do anything after I've found a circle. Is there any workaround for this?


Solution

  • The System.Drawing types provided in the Shim Drawing NuGet package, are only intended for internal use by the corresponding Portable Accord (and Portable AForge) libraries.

    Instead of using Graphics to draw on the bitmap image object, you should instead cast bitmap to the appropriate image type on the platform you are working on (WriteableBitmap on Windows, Android.Graphics.Bitmap on Android and CGImage on iOS) and use the drawing tools available on each specific platform.