Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
private void ProcessImage(Bitmap bitmap)
        {
            // lock image
            BitmapData bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
            ImageLockMode.ReadWrite, bitmap.PixelFormat);

           
            BlobCounter blobCounter = new BlobCounter();

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

            blobCounter.ProcessImage(bitmapData);
            Blob[] blobs = blobCounter.GetObjectsInformation();
            bitmap.UnlockBits(bitmapData);
            
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();
           Bitmap newBitmap = new Bitmap(bitmap.Width, bitmap.Height);
            Graphics g = Graphics.FromImage(newBitmap);
            g.DrawImage(bitmap, 0, 0);
          
            System.Drawing.Pen redPen = new System.Drawing.Pen(System.Drawing.Color.Red, 1);
            System.Drawing.Pen yellowPen = new System.Drawing.Pen(System.Drawing.Color.Yellow, 1);
            System.Drawing.Pen greenPen = new System.Drawing.Pen(System.Drawing.Color.Green, 1);
            System.Drawing.Pen bluePen = new System.Drawing.Pen(System.Drawing.Color.Blue, 1);

            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
                AForge.Point center;
                float radius;

                if (shapeChecker.IsCircle(edgePoints, out center, out radius))
                {
                    g.DrawEllipse(redPen,
                    (float)(center.X - radius), (float)(center.Y - radius),
                    (float)(radius * 2), (float)(radius * 2));
                    X = center.X;
                    Y = center.Y;
                    
                    //MessageBox.Show("X = " +X,"Y= " +Y);
                    CreateDataTable();
                    MessageBox.Show("");
                    d++;
                }
                else
                
                {
                    List<IntPoint> corners;
                   
                    if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
                    {
                        if (shapeChecker.CheckPolygonSubType(corners) == PolygonSubType.Rectangle)
                        {
                            g.DrawPolygon(bluePen, ToPointsArray(corners));
                          //CreateDataTable();
                        
                        }
                   }
                }
            }

            redPen.Dispose();
            greenPen.Dispose();
            bluePen.Dispose();
            yellowPen.Dispose();
            g.Dispose();
            System.Windows.Media.Imaging.BitmapSource b = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(),
                   IntPtr.Zero,
                   System.Windows.Int32Rect.Empty,
                    BitmapSizeOptions.FromWidthAndHeight(bitmap.Width, bitmap.Height));
            imgupload.Source = b;
        }



I m using AForge Library ti detect circles and rectangles from OMR sheet.
It will detect only not filled circles. if i want to detect filled circles then it will not work perfectly..
Posted
Updated 19-Mar-15 21:24pm
v4
Comments
Sergey Alexandrovich Kryukov 18-Mar-15 7:43am    
Are you using AForge.NET here or what? You need to ask your questions properly, provide all information on what you are using. Just the code dump is not very useful.
—SA
Member 9438748 20-Mar-15 1:28am    
sorry.. and yes i m useing the AForge library. for circles and rectangles detect.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900