AForge.NET

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

Finding a check in an image

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

Finding a check in an image

Postby stevew » Mon Jun 20, 2016 3:39 pm

I can only seem to find the outside border of the image, but no the check image within, using SimpleShapeChecker. Any hints ?

Code: Select all
            Bitmap image = _latestFrame;

            // locating objects
            BlobCounter blobCounter = new BlobCounter();

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

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

            // check for rectangles
            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

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

                // use the shape checker to extract the corner points
                if (shapeChecker.IsQuadrilateral(edgePoints, out cornerPoints))
                {
                    // 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));
                        }

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

                        image.Save("c:\\temp\\rectangles.jpg",ImageFormat.Jpeg);
                    }
                }
            }
stevew
 
Posts: 2
Joined: Mon Jun 20, 2016 3:36 pm

Re: Finding a check in an image

Postby andrew.kirillov » Tue Jun 21, 2016 7:04 am

Most probably your image is wrong and you did not read documentation. BlobCounter expects black background and white objects. If you are processing scanned document as is, then it is your fault.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Finding a check in an image

Postby stevew » Tue Jun 21, 2016 12:38 pm

Actually, that is not true. It DOES work fine with a scanned check, on an all-white background. It finds the check just fine.
stevew
 
Posts: 2
Joined: Mon Jun 20, 2016 3:36 pm

Re: Finding a check in an image

Postby andrew.kirillov » Tue Jun 21, 2016 2:00 pm

stevew wrote:It DOES work fine with a scanned check, on an all-white background.

OK, fine. It is not designed to work this way however. Anyway, since there is no sample image provided, I can not really comment something not working as expected.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK




Return to Image Processing and Computer Vision

cron