vendredi 6 décembre 2019

Count blob just once

Im working on a blob counting program that counts blob when it crosses a line. I processed and detected the blob and got the centroid of the blob, i also have the centroid of the line. So I created an if statement that if blobcentroid.y >= linecentroid.y then count++ . But the problem is that the program freezes and keeps counting blob until a new blob is in the frame. How do I fix this?

Code:

           Image<Gray, byte> threshedimg = new Image<Gray, byte>(imgGrayColorFiltered.Bitmap);
           Image<Bgr, byte> newimg = new Image<Bgr, byte>(threshedimg.Bitmap);

           CvInvoke.Threshold(threshedimg, threshedimg, tthreshold.Value, 255, Emgu.CV.CvEnum.ThresholdType.Binary);


           _blobDetector22.Detect(threshedimg, blobs1);
           blobs1.FilterByArea(10, int.MaxValue);

           float scale1 = (threshedimg.Width + threshedimg.Width) / 2.0f;
           _tracker22.Update(blobs1, 0.01 * scale1, 5, 5);

           Bitmap drawrect = new Bitmap(threshedimg.Bitmap);
           foreach (var pair1 in _tracker22)
           {
               b1 = pair1.Value;                 
               CvInvoke.Rectangle(newimg, b1.BoundingBox, new MCvScalar(255, 0, 0), 5);
               CvInvoke.PutText(newimg, b1.Id.ToString(), new System.Drawing.Point((int)Math.Round(b1.Centroid.X), (int)Math.Round(b1.Centroid.Y)), FontFace.HersheyPlain, 3.0, new MCvScalar(0, 0, 255), 2);

           }

           pictureBox1.Image = newimg.Bitmap;

           if (b1.Centroid.Y > linecentroid.Y)
           {
               increment++;
               label1.Text = increment.ToString();
           }

Aucun commentaire:

Enregistrer un commentaire