Esempio n. 1
0
        private void Track()
        {
            if (image == null)
            {
                return;
            }

            // calculate the back projection of the current image on top of the initial histogram.
            using (CVImage bp = image.CalcBackProject(this.initialHistogram))
            {
                // show the back projection.
                backProjectImage.Image = bp.ToBitmap();

                // calculate mean shift with user parameters and region of interest.
                CVConnectedComp conn = bp.MeanShift(originalImage.SelectionRect, Iterations);

                // update region of interest according to mean shift result.
                originalImage.SelectionRect = conn.Rect;
            }

            // rotate update counter only if rate != 0.
            if (UpdateHistogramRate != 0)
            {
                updateHistoCounter = (updateHistoCounter + 1) % UpdateHistogramRate;

                // update histogram is counter reached 0.
                if (updateHistoCounter == 0)
                {
                    UpdateHistogram();
                }
            }

            // refresh images.
            RefreshImages();
        }