ProcessFrame() public method

Processes a new video frame.
public ProcessFrame ( UnmanagedImage frame ) : void
frame Accord.Imaging.UnmanagedImage
return void
Exemplo n.º 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);
        }