示例#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 extern static void cvBGCodeBookClearStale(
     ref MCvBGCodeBookModel model,
     int staleThresh,
     Rectangle roi,
     IntPtr mask);
示例#3
0
 public extern static int cvBGCodeBookDiff(
     ref MCvBGCodeBookModel model,
     IntPtr image,
     IntPtr fgmask,
     Rectangle roi);
示例#4
0
 public extern static void cvBGCodeBookUpdate(
     ref MCvBGCodeBookModel model,
     IntPtr image,
     Rectangle roi,
     IntPtr mask);