Ejemplo n.º 1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            BitmapFilter.NegativeThreshold(ref loaded, ref processed, 174);
            pictureBox1.Image = processed;
            double sum = 0;
            //locate objects
            BlobCounter blobCounter = new BlobCounter();

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

            Graphics g      = Graphics.FromImage(processed);
            Pen      redPen = new Pen(Color.Red, 2);

            SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

            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,
                                  (int)(center.X - radius),
                                  (int)(center.Y - radius),
                                  (int)(radius * 2),
                                  (int)(radius * 2));

                    if (blobs[i].Area >= 240 && blobs[i].Area <= 290)
                    {
                        sum += 0.05;
                    }
                    if (blobs[i].Area >= 315 && blobs[i].Area <= 360)
                    {
                        sum += 0.1;
                    }
                    if (blobs[i].Area >= 420 && blobs[i].Area <= 500)
                    {
                        sum += 0.25;
                    }
                    if (blobs[i].Area >= 610 && blobs[i].Area <= 680)
                    {
                        sum += 1;
                    }
                    if (blobs[i].Area >= 760 && blobs[i].Area <= 840)
                    {
                        sum += 5;
                    }
                }
            }


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


            MessageBox.Show("Total: " + sum + "\nCount of coins: " + blobs.Length);
            pictureBox1.Image = loaded;
        }