Ejemplo n.º 1
0
        private void ShowFrames(object dontCare)
        {
            for (; ;)
            {
                if (m_ActualFrame < m_ExpectedFrame) // We're behind
                {
                    if (m_Capture.Grab())            // So grab the next frame, but don't process it
                    {
                        m_ActualFrame++;
                        m_FramesDropped++;
                    }
                    else       // No frames left. So exit loop
                    {
                        m_Playing = false;

                        if (m_Timer != null)
                        {
                            m_Timer.Change(-1, -1);
                            m_Timer = null;
                        }
                        return;
                    }
                }
                else if (m_ActualFrame > m_ExpectedFrame)
                {
                    Thread.Sleep(10);
                }
                else
                {
                    m_ActualFrame++;
                    Image <Bgr, byte> img = m_Capture.QueryFrame();
                    if (img != null)
                    {
                        Image <Bgr, byte> resized = img; //.Rotate(-5, new Bgr(System.Drawing.Color.Blue)); // img.Resize(720, 1280, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);

                        m_Engine.ProcessNextFrame(resized);
                        var imageToShow = m_Engine.DebugImage;
                        //var imageToShow = Engine.ImageProcess.ThresholdHsv(img, 14, 37, 150, 256, 80, 256).Erode(2).Dilate(1).Erode(1);
                        //var imageToShow = Engine.ImageProcess.PitchEdges(img);

                        Dispatcher.Invoke(new Action(() =>
                        {
                            if (imageToShow != null)
                            {
                                vidImage.Source = UI.Utils.BitmapSourceConvert.ToBitmapSource(imageToShow);
                            }
                            //.Resize(540, 960, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC));
                            labelFrameNumber.Content       = "Frame: " + m_ActualFrame;
                            labelBallDescription.Content   = m_Engine.Ball.ToString();
                            labelPossessionSummary.Content = m_Engine.Stats.GetPossessionSummary();
                            if (m_ActualFrame % 10 == 0)
                            {
                                labelHighestSpeedDesc.Content = m_Engine.Stats.GetRecentHighestSpeedDesc();
                            }
                        }));
                        resized = null;
                        img     = null;

                        //GC.Collect();
                    }
                    else
                    {
                        m_Playing = false;

                        if (m_Timer != null)
                        {
                            m_Timer.Change(-1, -1);
                            m_Timer = null;
                        }
                        return;
                    }
                }
            }
        }