Пример #1
0
        public static void TestCodeBook()
        {
            int learningFrames = 40;

            using (Capture capture = new Capture("tree.avi"))
                using (BGCodeBookModel <Ycc> bgmodel = new BGCodeBookModel <Ycc>())
                {
                    #region Set color thresholds values
                    MCvBGCodeBookModel param = bgmodel.MCvBGCodeBookModel;
                    param.modMin[0]            = param.modMin[1] = param.modMin[2] = 3;
                    param.modMax[0]            = param.modMax[1] = param.modMax[2] = 10;
                    param.cbBounds[0]          = param.cbBounds[1] = param.cbBounds[2] = 10;
                    bgmodel.MCvBGCodeBookModel = param;
                    #endregion

                    ImageViewer  viewer       = new ImageViewer();
                    int          count        = 0;
                    EventHandler processFrame = delegate(Object sender, EventArgs e)
                    {
                        Image <Bgr, Byte> img = capture.QueryFrame();
                        if (img == null)
                        {
                            return;
                        }
                        Image <Gray, byte> mask = new Image <Gray, Byte>(img.Size);
                        mask.SetValue(255);

                        viewer.Text = String.Format("Processing {0}th image. {1}", count++, learningFrames > 0 ? "(Learning)" : String.Empty);

                        using (Image <Ycc, Byte> ycc = img.Convert <Ycc, Byte>()) //using YCC color space for BGCodeBook
                        {
                            bgmodel.Update(ycc, ycc.ROI, mask);

                            if (learningFrames == 0) //training is completed
                            {
                                bgmodel.ClearStale(bgmodel.MCvBGCodeBookModel.t / 2, ycc.ROI, mask);
                            }

                            learningFrames--;
                            Image <Gray, Byte> m = bgmodel.ForgroundMask.Clone();
                            if (count == 56)
                            {
                                m = bgmodel.ForgroundMask.Clone();
                            }
                            //m._EqualizeHist();
                            viewer.Image = m;
                            //viewer.Image = img;
                            System.Threading.Thread.Sleep(100);
                        }

                        img.Dispose();
                    };

                    Application.Idle += processFrame;

                    viewer.ShowDialog();
                }
        }
Пример #2
0
        public static void TestCodeBook()
        {
            int learningFrames = 40;
             using (Capture capture = new Capture("tree.avi"))
             using (BGCodeBookModel<Ycc> bgmodel = new BGCodeBookModel<Ycc>())
             {
            #region Set color thresholds values
            MCvBGCodeBookModel param = bgmodel.MCvBGCodeBookModel;
            param.modMin[0] = param.modMin[1] = param.modMin[2] = 3;
            param.modMax[0] = param.modMax[1] = param.modMax[2] = 10;
            param.cbBounds[0] = param.cbBounds[1] = param.cbBounds[2] = 10;
            bgmodel.MCvBGCodeBookModel = param;
            #endregion

            ImageViewer viewer = new ImageViewer();
            int count = 0;
            EventHandler processFrame = delegate(Object sender, EventArgs e)
            {
               Image<Bgr, Byte> img = capture.QueryFrame();
               if (img == null)
               {
                  return;
               }
               Image<Gray, byte> mask = new Image<Gray, Byte>(img.Size);
               mask.SetValue(255);

               viewer.Text = String.Format("Processing {0}th image. {1}", count++, learningFrames > 0 ? "(Learning)" : String.Empty);

               using (Image<Ycc, Byte> ycc = img.Convert<Ycc, Byte>()) //using YCC color space for BGCodeBook
               {
                  bgmodel.Update(ycc, ycc.ROI, mask);

                  if (learningFrames == 0) //training is completed
                     bgmodel.ClearStale(bgmodel.MCvBGCodeBookModel.t / 2, ycc.ROI, mask);

                  learningFrames--;
                  Image<Gray, Byte> m = bgmodel.ForgroundMask.Clone();
                  if (count == 56)
                  {
                     m = bgmodel.ForgroundMask.Clone();
                  }
                  //m._EqualizeHist();
                  viewer.Image = m;
                  //viewer.Image = img;
                  System.Threading.Thread.Sleep(100);
               }

               img.Dispose();
            };

            Application.Idle += processFrame;

            viewer.ShowDialog();
             }
        }
Пример #3
0
        public void TestCodeBookBGModel()
        {
            using (Capture capture = new Capture())
                using (BGCodeBookModel <Bgr> model = new BGCodeBookModel <Bgr>())
                {
                    ImageViewer        viewer = new ImageViewer();
                    Image <Gray, byte> fgMask = capture.QueryFrame().Convert <Gray, Byte>();

                    Application.Idle += delegate(Object sender, EventArgs args)
                    {
                        Image <Bgr, Byte> frame = capture.QueryFrame();
                        model.Update(frame);
                        viewer.Image = model.ForgroundMask;
                    };
                    viewer.ShowDialog();
                }
        }
Пример #4
0
        public void TestCodeBookBGModel()
        {
            using (Capture capture = new Capture())
             using (BGCodeBookModel<Bgr> model = new BGCodeBookModel<Bgr>())
             {
            ImageViewer viewer = new ImageViewer();
            Image<Gray, byte> fgMask = capture.QueryFrame().Convert<Gray, Byte>();

            Application.Idle += delegate(Object sender, EventArgs args)
            {
               Image<Bgr, Byte> frame = capture.QueryFrame();
               model.Update(frame);
               viewer.Image = model.ForgroundMask;
            };
            viewer.ShowDialog();
             }
        }