/// <summary> /// Instatiates a ready-to-go median flow tracker. /// All of its initial configuration is done here. /// </summary> private void InstantiateTracker() { // grid bounding box _gridBb = new MedianFlowTrackerBoundingBox ( new Size(10, 10), new SizeF(5, 5) ); // lucas kanade tracker _lkTracker = new LucasKanadeTracker( new Size(11, 11), 2, new MCvTermCriteria(20, 0.03), LKFLOW_TYPE.DEFAULT, LKFLOW_TYPE.CV_LKFLOW_PYR_A_READY | LKFLOW_TYPE.CV_LKFLOW_PYR_B_READY ); // fb error and ncc calculators _fbErrorCalc = Service.FBError; _nccCalc = Service.NCC; // patch size for calculating NCC _patchSize = new Size(11, 11); // MAD treshold _madTrashold = 10; // ** instantiate the median flow tracker ** _tracker = new MedianFlowTracker( _gridBb, _lkTracker, _fbErrorCalc, _nccCalc, _patchSize, _madTrashold ); // initial frame _initialFrame = new Image <Gray, byte>(Path.Combine(_resourceDir, "violeta_5.jpg")); // initial bounding box _initialBB = new BoundingBox( new PointF(90, 81), new SizeF(70, 40) ); // ** initialize the median flow tracker ** _tracker.Initialize(_initialFrame, _initialBB); }
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); }