Beispiel #1
0
        void kinect_OnDepthFrame()
        {
            DateTime time = DateTime.Now;

            if (!Ready)
            {
                Console.WriteLine("");
            }
            var balls = detector.Detect(kinect);

            foreach (var ball in balls)
            {
                Frame3D frame = new Frame3D()
                {
                    Ball = ball, Time = time
                };
                tracker.Push(frame);
            }

            Ready = false;
            counter++;

            /*if (counter > 24)
             * {
             *  stream.Write(Encoding.UTF8.GetBytes("test".ToCharArray()), 0, "test".Length);
             *  counter = 0;
             * }*/

            DisplayOut = detector.DetectorOverlay.Copy();
            drawPrediction();

            Ready = true;
        }
Beispiel #2
0
        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);
        }