Beispiel #1
0
        /// <summary>
        /// Create a auto blob tracker using the specific parameters
        /// </summary>
        /// <param name="param">The parameters for this blob tracker auto</param>
        public BlobTrackerAuto(BlobTrackerAutoParam <TColor> param)
        {
            _param = param;
            MCvBlobTrackerAutoParam1 p = _param.MCvBlobTrackerAutoParam1;

            _ptr = CvInvoke.CvCreateBlobTrackerAuto1(ref p);
        }
 /// <summary>
 /// Create a default auto blob tracker 
 /// </summary>
 public BlobTrackerAuto()
 {
    BlobTrackerAutoParam<TColor> param = new BlobTrackerAutoParam<TColor>();
    param.FGDetector = new FGDetector<TColor>(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD);
    _param = param;
    MCvBlobTrackerAutoParam1 p = _param.MCvBlobTrackerAutoParam1;
    _ptr = BlobTrackerAutoInvoke.CvCreateBlobTrackerAuto1(ref p);
 }
Beispiel #3
0
        public void TestBlobColor()
        {
            int width = 300;
             int height = 400;
             Image<Bgr, Byte> bg = new Image<Bgr, byte>(width, height);
             bg.SetRandNormal(new MCvScalar(), new MCvScalar(100, 100, 100));

             Size size = new Size(width / 10, height / 10);
             Point topLeft = new Point((width >> 1) - (size.Width >> 1), (height >> 1) - (size.Height >> 1));

             Rectangle rect = new Rectangle(topLeft, size);

             BlobTrackerAutoParam<Bgr> param = new BlobTrackerAutoParam<Bgr>();
             param.BlobDetector = new BlobDetector(Emgu.CV.CvEnum.BLOB_DETECTOR_TYPE.CC);
             //param.FGDetector = new FGDetector<Gray>(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD);
             param.BlobTracker = new BlobTracker(Emgu.CV.CvEnum.BLOBTRACKER_TYPE.MSFGS);
             param.FGTrainFrames = 5;
             BlobTrackerAuto<Bgr> tracker = new BlobTrackerAuto<Bgr>(param);

             //ImageViewer viewer = new ImageViewer();
             //viewer.Show();
             for (int i = 0; i < 20; i++)
             {
            using (Image<Bgr, Byte> img1 = bg.Copy())
            {
               rect.Offset(5, 0); //shift the rectangle 5 pixels horizontally
               img1.Draw(rect, new Bgr(Color.Red), -1);
               tracker.Process(img1);
               //viewer.Image = img1;
            }
             }

             //MCvBlob blob = tracker[0];
             //int id = blob.ID;
             //ImageViewer.Show(forground);
        }
Beispiel #4
0
        public void TestBlobTracking()
        {
            Capture capture = new Capture();

             ImageViewer viewer = new ImageViewer();

             BlobTrackerAutoParam<Gray> param = new BlobTrackerAutoParam<Gray>();
             //param.BlobDetector = new BlobDetector(Emgu.CV.CvEnum.BLOB_DETECTOR_TYPE.CC);
             param.FGDetector = new FGDetector<Gray>(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD);
             //param.BlobTracker = new BlobTracker(Emgu.CV.CvEnum.BLOBTRACKER_TYPE.CCMSPF);
             param.FGTrainFrames = 10;
             BlobTrackerAuto<Gray> tracker = new BlobTrackerAuto<Gray>(param);

             MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0);

             Application.Idle += new EventHandler(delegate(object sender, EventArgs e)
             {
            tracker.Process(capture.QuerySmallFrame().PyrUp().Convert<Gray, Byte>());

            Image<Gray, Byte> img = tracker.ForgroundMask;
            //viewer.Image = tracker.GetForgroundMask();
            foreach (MCvBlob blob in tracker)
            {
               img.Draw(Rectangle.Round(blob), new Gray(255.0), 2);
               img.Draw(blob.ID.ToString(), ref font, Point.Round(blob.Center), new Gray(255.0));
            }
            viewer.Image = img;
             });
             viewer.ShowDialog();
        }