Example #1
0
        public void FindObject_2ReliableShifts()
        {
            // 1.1 arrange - typical case
            ArrangeTypicalCase();

            // 1.2 arrange - change fb error and ncc for each point.
            // Exactly 2 shifts have both fbError <= median(fbError) and ncc >= median(ncc)
            _service.FBErrorsList = new List <List <float> >();
            _service.FBErrorsList.Add(new List <float>()
            {
                0, 0, 0,
                2, 2, 2
            });
            _service.NCCsList = new List <List <float> >();
            _service.NCCsList.Add(new List <float>()
            {
                1, 1, -1,
                -1, -1, 1
            });

            // 2. define expected
            IBoundingBox expectedBB = new BoundingBoxStub(
                new PointF(2, 3.5f),
                new SizeF(6, 2)
                );
            MedianFlowTrackerStatus expectedStatus = MedianFlowTrackerStatus.OK;

            // 3. get actual
            IBoundingBox            actualBB     = _tracker.FindObject(new Image <Gray, byte>(_frameSize));
            MedianFlowTrackerStatus actualStatus = _tracker.Status;

            // 4. assert
            Assert.IsTrue((actualBB as BoundingBoxStub).IsEqualTo(expectedBB as BoundingBoxStub));
            Assert.AreEqual(expectedStatus, actualStatus);
        }
Example #2
0
 internal bool IsEqualTo(BoundingBoxStub expectedBB)
 {
     return(CenterStub == expectedBB.CenterStub && SizeStub == expectedBB.SizeStub);
 }
Example #3
0
        public void FindObject_PostInit()
        {
            // 1.1 arrange - typical case
            ArrangeTypicalCase();

            // 1.2. arrange data for the 2nd frame
            //      1.2.1 bounding box
            PointF bbCenter = new PointF(3, 4);
            SizeF  bbSize   = new SizeF(6, 2);

            PointF[] bbVisiblePoints = new PointF[] {
                new PointF(0, 3), new PointF(2, 3), new PointF(4, 3), new PointF(6, 3),
                new PointF(0, 5), new PointF(2, 5), new PointF(4, 5), new PointF(6, 5)
            };
            IMedianFlowTrackerBoundingBox bb = new MedianFlowTrackerBoundingBoxStub(bbCenter, bbSize, bbVisiblePoints);

            _bb.HardcodedNextBB = (bb as MedianFlowTrackerBoundingBoxStub);

            //      1.2.2 arrange - set forward and backward points.
            //                      All points are tracked both forward and backward succesfully.
            _LKtracker.ForwardPointsList.Add(new PointF[] {
                new PointF(1, 3), new PointF(3, 3), new PointF(5, 3), new PointF(7, 3),
                new PointF(1, 5), new PointF(3, 5), new PointF(5, 5), new PointF(7, 5)
            });
            _LKtracker.BackwardPointsList.Add(new PointF[] {
                new PointF(0, 3), new PointF(2, 3), new PointF(4, 3), new PointF(6, 3),
                new PointF(0, 5), new PointF(2, 5), new PointF(4, 5), new PointF(6, 5)
            });
            _LKtracker.ForwardStatusList.Add(new byte[] {
                1, 1, 1, 1,
                1, 1, 1, 1
            });
            _LKtracker.BackwardStatusList.Add(new byte[] {
                1, 1, 1, 1,
                1, 1, 1, 1
            });

            //      1.2.3 arrange - change fb error for each point.
            //                      Every point should be reliable.
            _service.FBErrorsList.Add(new List <float>()
            {
                0, 0, 0, 0,
                0, 0, 0, 0
            });
            _service.NCCsList.Add(new List <float>()
            {
                1, 1, 1, 1,
                1, 1, 1, 1
            });

            // 1.3. arrange - call tracker the first time
            _tracker.FindObject(new Image <Gray, byte>(_frameSize));

            // 2. define expected
            IBoundingBox expectedBB = new BoundingBoxStub(
                new PointF(4, 4),
                new SizeF(6, 2)
                );
            MedianFlowTrackerStatus expectedStatus = MedianFlowTrackerStatus.OK;

            // 3. get actual - call tracker for the second time
            IBoundingBox            actualBB     = _tracker.FindObject(new Image <Gray, byte>(_frameSize));
            MedianFlowTrackerStatus actualStatus = _tracker.Status;

            // 4. assert
            Assert.AreEqual((expectedBB as BoundingBoxStub).CenterStub, (actualBB as BoundingBoxStub).CenterStub);
            Assert.AreEqual((expectedBB as BoundingBoxStub).SizeStub, (actualBB as BoundingBoxStub).SizeStub);
            Assert.AreEqual(expectedStatus, actualStatus);
        }