Example #1
0
File: Tracker.cs Project: jarsam/P5
        public void Push(Frame3D frame)
        {
            //try to fit to existing frames

            foreach (var btd in trackData)
            {
                Vector ppos;
                double dThresh = 0.0f;

                if (btd.ProjFit != null)
                {
                    ppos = btd.ProjFit.PredictPos(frame.Time); //use predicted pos

                    if (btd.ProjFit is ProjFitQuad)
                    {
                        dThresh = distThresh;
                    }
                    else if (btd.ProjFit is ProjFitLin)
                    {
                        dThresh = distThresh * 1;
                    }
                }
                else
                {
                    ppos    = btd.Frames.Last().Ball.Position; //just use the only known pos
                    dThresh = distThresh * 1;
                }


                double dist = (ppos - frame.Ball.Position).Norm(2);
                if (dist <= dThresh)
                {
                    btd.Frames.Add(frame);

                    if (btd.Frames.Count >= minPointForInterp) //if we have a decent # of data points
                    {
                        btd.ProjFit = new ProjFitQuad();
                        btd.ProjFit.Train(btd.Frames);
                    }
                    else if (btd.Frames.Count >= 3)
                    {
                        btd.ProjFit = new ProjFitLin();
                        btd.ProjFit.Train(btd.Frames.OrderByDescending(f => f.Time.Ticks).Take(2).ToList());
                    }

                    return;
                }
            }


            //ball not found in predictions of existing balls --  must be new
            BallTrackData new_btd = new BallTrackData();

            new_btd.ID = i++;
            new_btd.Frames.Add(frame);
            trackData.Add(new_btd);
        }
Example #2
0
File: Tracker.cs Project: jarsam/P5
        double ballTrackDataActivity(BallTrackData btd)
        {
            Vector lastPos = btd.Frames.First().Ball.Position;
            double dsum    = 0;

            foreach (var f in btd.Frames)
            {
                dsum   += (f.Ball.Position - lastPos).Norm(2);
                lastPos = f.Ball.Position;
            }
            return(dsum);
        }
Example #3
0
        public void Update()
        {
            tracker.Update();

            ActiveBall = tracker.GetMostActiveBallProj();
        }