Exemplo n.º 1
0
        private void meanShiftNoMask_SelectionChanged(object sender, EventArgs e)
        {
            using (CVImage frame = videoPlayer.LastFrame.CopyRegion(meanShiftNoMask.SelectionRect))
            {
                if (histNoMask != null)
                {
                    histNoMask.Dispose();
                }
                histNoMask = frame.CalcHistogram(Bins);
                noMaskHist.BinsPerChannel = Bins;
                noMaskHist.ShowHistogram(frame);
            }

            NextFrame(false);
        }
Exemplo n.º 2
0
        private void CalculateMaskedHistogram()
        {
            if (videoPlayer.LastFrame == null)
            {
                return;
            }

            using (CVImage frame = videoPlayer.LastFrame.CopyRegion(meanShift.SelectionRect))
            {
                // create a list of real fg and bg markers.
                List <Point> realFg = new List <Point>(meanShift.GetMarkerLocations(Color.Blue));
                List <Point> realBg = new List <Point>(meanShift.GetMarkerLocations(Color.Red));

                // create the histogram mask.
                using (CVImage mask = MaskedHistogram.PrepareMask(frame, realFg.ToArray(), realBg.ToArray(), includeNeautral.Checked, ffThresh.Value))
                {
                    maskPicture.Image = mask.ToBitmap();

                    // show mask histogram to user interface.
                    maskHistogram.BinsPerChannel = Bins;
                    maskHistogram.ShowHistogram(frame, mask);

                    // calculate new histogram (dispose old one if exist).
                    if (hist != null)
                    {
                        hist.Dispose();
                    }
                    hist = frame.CalcHistogram(Bins, mask);

                    // apply mask to overlay (just for ui).
                    using (CVImage masked = MaskedHistogram.ApplyMask(frame, mask))
                    {
                        maskOverlay.Image = masked.ToBitmap();
                    }
                }
            }

            NextFrame(false);
        }