Continuously Adaptive Mean Shift (Camshift) Object Tracker

Camshift stands for "Continuously Adaptive Mean Shift". It combines the basic Mean Shift algorithm with an adaptive region-sizing step. The kernel is a step function applied to a probability map. The probability of each image pixel is based on color using a method called histogram backprojection.

The implementation of this code has used Gary Bradski's original publication, the OpenCV Library and the FaceIt implementation as references. The OpenCV library is distributed under a BSD license. FaceIt is distributed under a MIT license. The original licensing terms for FaceIt are described in the source code and in the Copyright.txt file accompanying the framework.

References: G.R. Bradski, Computer video face tracking for use in a perceptual user interface, Intel Technology Journal, Q2 1998. Available on: ftp://download.intel.com/technology/itj/q21998/pdf/camshift.pdf R. Hewitt, Face tracking project description: Camshift Algorithm. Available on: http://www.robinhewitt.com/research/track/camshift.html OpenCV Computer Vision Library. Available on: http://sourceforge.net/projects/opencvlibrary/ FaceIt object tracking in Flash AS3. Available on: http://www.libspark.org/browser/as3/FaceIt

Наследование: IObjectTracker
Пример #1
20
        public void ProcessFrame()
        {
            Bitmap frame = Properties.Resources.lena_color_small;
            Rectangle trackedArea = new Rectangle(0, 0, 50, 50);

            UnmanagedImage uframe = UnmanagedImage.FromManagedImage(frame);

            // initialization
            Camshift target = new Camshift(trackedArea);
            target.Conservative = false;
            target.Mode = CamshiftMode.RGB;
            target.Smooth = false;
            target.AspectRatio = 0;
            target.Extract = true;

            target.ProcessFrame(uframe);
            var to = target.TrackingObject;
            var window = target.SearchWindow;
            Rectangle expected = new Rectangle(0, 0, 50, 50);
            Assert.AreEqual(expected, window);

            // Frame 1 - entire image
            target.ProcessFrame(uframe);

            to = target.TrackingObject;
            window = target.SearchWindow;

            Assert.AreEqual(0.9188701900796201, to.Angle, 0.001);
            Assert.AreEqual((int)47.57993716803177, to.Rectangle.Width, 0.01);
            Assert.AreEqual((int)57.3831709184114, to.Rectangle.Height, 0.05);

            Assert.AreEqual(new Rectangle(0, 0, 52, 62), window);

            Assert.IsNotNull(to.Image);
            Assert.AreEqual(47, to.Image.Width);
            Assert.AreEqual(54, to.Image.Height);


            // Frame 1 - conservative
            target = new Camshift(uframe, trackedArea);
            target.Conservative = true;
            target.ProcessFrame(uframe);
            target.Extract = false;

            to = target.TrackingObject;
            window = target.SearchWindow;

            Assert.AreEqual(0.0, to.Angle);
            Assert.AreEqual((int)57.7234764, to.Rectangle.Width, 0.000001);
            Assert.AreEqual((int)57.7234764, to.Rectangle.Height, 0.000005);
            Assert.AreEqual(25, to.Center.X);
            Assert.AreEqual(25, to.Center.Y);

            Assert.IsNull(to.Image);

            Assert.AreEqual(new Rectangle(0, 0, 63, 63), window);
        }
Пример #2
1
        // Close current video source
        private void CloseVideoSource()
        {
            // set busy cursor
            this.Cursor = Cursors.WaitCursor;

            // stop current video source
            videoSourcePlayer.SignalToStop();

            // wait 2 seconds until camera stops
            for (int i = 0; (i < 50) && (videoSourcePlayer.IsRunning); i++)
            {
                Thread.Sleep(100);
            }
            if (videoSourcePlayer.IsRunning)
                videoSourcePlayer.Stop();

            // stop timers
            timer.Stop();

            // reset motion detector
            tracker = new Camshift();
            tracker.Mode = hSLToolStripMenuItem.Checked ? CamshiftMode.HSL :
                           mixedToolStripMenuItem.Checked ? CamshiftMode.Mixed :
                           CamshiftMode.RGB;
            tracker.Conservative = true;
            tracker.AspectRatio = 1.5f;

            videoSourcePlayer.BorderColor = Color.Black;
            this.Cursor = Cursors.Default;
        }
Пример #3
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="HeadController"/> class.
        /// </summary>
        /// 
        public HeadController()
        {
            // Setup tracker
            tracker = new Camshift();
            tracker.Mode = CamshiftMode.RGB;
            tracker.Conservative = true;
            tracker.AspectRatio = 1.5f;

            // Setup detector
            detector = new HaarObjectDetector(new FaceHaarCascade());
            detector.MinSize = new Size(25, 25);
            detector.SearchMode = ObjectDetectorSearchMode.Single;
            detector.ScalingFactor = 1.2f;
            detector.ScalingMode = ObjectDetectorScalingMode.GreaterToSmaller;

            xaxisRange = new IntRange(0, 320);
            yaxisRange = new IntRange(0, 240);
            scaleRange = new DoubleRange(0, Math.Sqrt(320 * 240));
            angleRange = new DoubleRange(0, 2 * Math.PI);
        }