AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Checkbox detection and its status checking

The forum is to discuss topics related to different areas of image processing and computer vision.

Checkbox detection and its status checking

Postby ashok » Wed Jul 27, 2016 7:43 am

Hi,

I have form which includes the checkboxes. I am trying to detect thee using blob process and Shapechecker for this. But I am unable to detect the checkboxes (Square/Rectangle). It detecting the squares but not all squares. I am using the below code to achieve this. Kindly help me to check the checked/unchecked status of the checkboxes.

Bitmap bitmap = new Bitmap(@"C:\OCRDemo\Source\transformed.jpg");
//Bitmap bitmap = (Bitmap)Bitmap.FromFile(@"C:\OCRDemo\Source\paper-form-2-transformed.jpg");
//Bitmap gray = AForge.Imaging.Image.CreateGrayscaleImage(200, 200);
Bitmap rgb = AForge.Imaging.Image.Clone(bitmap, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

// grayscale filter (BT709)
AForge.Imaging.Filters.Grayscale gr = new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721);
bitmap = gr.Apply(bitmap);

AForge.Imaging.Filters.Threshold th = new AForge.Imaging.Filters.Threshold(100);
bitmap = th.Apply(bitmap);

// locate objects using blob counter
BlobCounter bc = new BlobCounter();
bc.FilterBlobs = true;
bc.MinWidth = 5;
bc.MinHeight = 5;
// set ordering options
bc.ObjectsOrder = ObjectsOrder.Size;
bc.ProcessImage(bitmap);
Blob[] blobs = bc.GetObjectsInformation();
SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

for (int i = 0, n = blobs.Length; i < n; i++)
{
List<IntPoint> edgePoints = bc.GetBlobsEdgePoints(blobs[i]);

//AForge.Point center;
//float radius;
List<IntPoint> cornerPoints;

if (shapeChecker.IsQuadrilateral(edgePoints, out cornerPoints))
{
//Console.WriteLine(String.Format("X:{0}, Y:{1}, r:{2}", center.X, center.Y, radius));
// only do things if the corners form a rectangle
if (shapeChecker.CheckPolygonSubType(cornerPoints) == PolygonSubType.Rectangle)
{
// here i use the graphics class to draw an overlay, but you
// could also just use the cornerPoints list to calculate your
// x, y, width, height values.
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));
}




//System.Drawing.Image img = System.Drawing.Image.FromStream(new MemoryStream(imgData));
//Bitmap img = new Bitmap(new Bitmap(img));

Bitmap tempBitmap = new Bitmap(bitmap.Width, bitmap.Height);

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

rgb.Save(@"C:\OCRDemo\Source\result1.jpg");
}

}
// only do things if the corners form a rectangle
//if (shapeChecker.CheckPolygonSubType(cornerPoints) == PolygonSubType.Rectangle)
//{
// bc.ExtractBlobsImage(bitmap, blobs[i], true);
//}
}

Thanks in advance!
Ashok
ashok
 
Posts: 1
Joined: Wed Jul 27, 2016 7:29 am



Return to Image Processing and Computer Vision