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); }
private void ArrangeTypicalCase() { // 1. arrange // 1.1 initialize median flow tracker // 1.1.1 frame size _frameSize = new Size(8, 6); // 1.1.2 bounding box PointF bbCenter = new PointF(3.5f, 2.5f); SizeF bbSize = new SizeF(3, 1); PointF[] bbVisiblePoints = new PointF[] { new PointF(2, 2), new PointF(3, 2), new PointF(4, 2), new PointF(5, 2), new PointF(2, 3), new PointF(3, 3), new PointF(4, 3), new PointF(5, 3), }; _bb = new MedianFlowTrackerBoundingBoxStub(bbCenter, bbSize, bbVisiblePoints); // 1.1.3 lucas kanade tracker List <PointF[]> forwardPointsList = new List <PointF[]>(); forwardPointsList.Add(new PointF[] { new PointF(0, 3), new PointF(2, 3), new PointF(4, 0), new PointF(8, 0), new PointF(0, 5), new PointF(3, 1), new PointF(4, 5), new PointF(6, 5), }); List <PointF[]> backwardPointsList = new List <PointF[]>(); backwardPointsList.Add(new PointF[] { new PointF(2, 2), new PointF(3, 2), new PointF(7, 0), new PointF(8, 0), new PointF(2, 3), new PointF(6, 1), new PointF(4, 3), new PointF(-1, 5), }); List <byte[]> forwardStatusList = new List <byte[]>(); forwardStatusList.Add(new byte[] { 1, 1, 1, 0, 1, 1, 1, 1 }); List <byte[]> backwardStatusList = new List <byte[]>(); backwardStatusList.Add(new byte[] { 1, 1, 1, 1, 0, 1, 1, 1 }); _LKtracker = new LucasKanadeTrackerStub( forwardPointsList, backwardPointsList, forwardStatusList, backwardStatusList ); // 1.1.4. FBError and NCC calculators _service = new ServiceStub(); _service.FBErrorsList = new List <List <float> >(); _service.FBErrorsList.Add(new List <float>() { 0, 0, 2, 2, 0, 0 }); _service.NCCsList = new List <List <float> >(); _service.NCCsList.Add(new List <float>() { 1, 1, -1, -1, 1, 1 }); TLD.Model.MedianFlowTracker.FBError_Calculator fb_calc = _service.FBErrorStub; TLD.Model.MedianFlowTracker.NCC_Calculator ncc_calc = _service.NCCStub; // 1.1.5. MAD threshold _madThreshold = 10; // 1.1.6. instantiate and initialize _tracker = new MedianFlowTracker( _bb, _LKtracker, fb_calc, ncc_calc, new Size(2, 2), _madThreshold ); _tracker.Initialize(new Image <Gray, byte>(_frameSize), _bb); }