Long-term optical tracking is an important issue for many computer vision applications in real world scenario. The development in this area is very fragmented and this API is an unique interface useful for plug several algorithms and compare them. This work is partially based on [238] and [169] .
These algorithms start from a bounding box of the target and with their internal representation they avoid the drift during the tracking. These long-term trackers are able to evaluate online the quality of the location of the target in the new frame, without ground truth.
There are three main components: the TrackerContribSampler, the TrackerContribFeatureSet and the TrackerModel. The first component is the object that computes the patches over the frame based on the last target location. The TrackerContribFeatureSet is the class that manages the Features, is possible plug many kind of these (HAAR, HOG, LBP, Feature2D, etc). The last component is the internal representation of the target, it is the appearance model. It stores all state candidates and compute the trajectory (the most likely target states). The class TrackerTargetState represents a possible state of the target. The TrackerContribSampler and the TrackerContribFeatureSet are the visual representation of the target, instead the TrackerModel is the statistical model.
A recent benchmark between these algorithms can be found in [307]
Creating Your Own Tracker
If you want to create a new tracker, here's what you have to do. First, decide on the name of the class for the tracker (to meet the existing style, we suggest something with prefix "tracker", e.g. trackerMIL, trackerBoosting) – we shall refer to this choice as to "classname" in subsequent.
Declare your tracker in modules/tracking/include/opencv2/tracking/tracker.hpp. Your tracker should inherit from Tracker (please, see the example below). You should declare the specialized Param structure, where you probably will want to put the data, needed to initialize your tracker. You should get something similar to :
classCV_EXPORTS_WTrackerMIL : publicTracker
{
public:
structCV_EXPORTSParams
{
Params();
//parameters for samplerfloatsamplerInitInRadius; // radius for gathering positive instances during initintsamplerInitMaxNegNum; // # negative samples to use during initfloatsamplerSearchWinSize; // size of search windowfloatsamplerTrackInRadius; // radius for gathering positive instances during trackingintsamplerTrackMaxPosNum; // # positive samples to use during trackingintsamplerTrackMaxNegNum; // # negative samples to use during trackingintfeatureSetNumFeatures; // #featuresvoidread( constFileNode& fn );
voidwrite( FileStorage& fs ) const;
};
of course, you can also add any additional methods of your choice. It should be pointed out, however, that it is not expected to have a constructor declared, as creation should be done via the corresponding create() method.
Finally, you should implement the function with signature :
TrackerContribSampler is already instantiated, but you should define the sampling algorithm and add the classes (or single class) to TrackerContribSampler. You can choose one of the ready implementation as TrackerContribSamplerCSC or you can implement your sampling method, in this case the class must inherit TrackerContribSamplerAlgorithm. Fill the samplingImpl method that writes the result in "sample" output argument.
//sampler is the TrackerContribSamplerPtr<TrackerContribSamplerAlgorithm> CSCSampler = newTrackerContribSamplerCSC( CSCparameters );
if( !sampler->addTrackerSamplerAlgorithm( CSCSampler ) )
returnfalse;
//or add CSC sampler with default parameters//sampler->addTrackerSamplerAlgorithm( "CSC" );
TrackerContribFeatureSet
TrackerContribFeatureSet is already instantiated (as first) , but you should define what kinds of features you'll use in your tracker. You can use multiple feature types, so you can add a ready implementation as TrackerContribFeatureHAAR in your TrackerContribFeatureSet or develop your own implementation. In this case, in the computeImpl method put the code that extract the features and in the selection method optionally put the code for the refinement and selection of the features.
//featureSet is the TrackerContribFeatureSetPtr<TrackerFeature> trackerFeature = newTrackerContribFeatureHAAR( HAARparameters );
featureSet->addTrackerFeature( trackerFeature );
TrackerModel
TrackerModel is abstract, so in your implementation you must develop your TrackerModel that inherit from TrackerModel. Fill the method for the estimation of the state "modelEstimationImpl", that estimates the most likely target location, see [238] table I (ME) for further information. Fill "modelUpdateImpl" in order to update the model, see [238] table I (MU). In this class you can use the :cConfidenceMap and :cTrajectory to storing the model. The first represents the model on the all possible candidate states and the second represents the list of all estimated states.
Example of creating specialized TrackerModel TrackerMILModel : :
boolTrackerMIL::initImpl( constMat& image, constRect2d& boundingBox )
{
...
//model is the general TrackerModel field of the general Trackermodel = newTrackerMILModel( boundingBox );
...
}
In the last step you should define the TrackerStateEstimator based on your implementation or you can use one of ready class as TrackerStateEstimatorMILBoosting. It represent the statistical part of the model that estimates the most likely target state.
Example of creating specialized TrackerStateEstimator TrackerStateEstimatorMILBoosting : :
//model is the TrackerModel of your TrackerPtr<TrackerStateEstimatorMILBoosting> stateEstimator = newTrackerStateEstimatorMILBoosting( params.featureSetNumFeatures );
model->setTrackerStateEstimator( stateEstimator );
During this step, you should define your TrackerTargetState based on your implementation. TrackerTargetState base class has only the bounding box (upper-left position, width and height), you can enrich it adding scale factor, target rotation, etc.
Example of creating specialized TrackerTargetState TrackerMILTargetState : :
Class that manages the sampler in order to select regions for the update the model of the tracker [AAM] Sampling e Labeling. See table I and section III B. More...
Class that manages the sampler in order to select regions for the update the model of the tracker [AAM] Sampling e Labeling. See table I and section III B. More...
Compute the interaction matrix ( [136][55][56] ) for a set of 2D pixels. This is usually used in visual servoing applications to command a robot to move at desired pixel locations/velocities. By inverting this matrix, one can estimate camera spatial velocity i.e., the twist.
Compute the camera twist from a set of 2D pixel locations, their velocities, depth values and intrinsic parameters of the camera. The pixel velocities are usually obtained from optical flow algorithms, both dense and sparse flow can be used to compute the flow between images and duv computed by dividing the flow by the time interval between the images.
Compute the interaction matrix ( [136][55][56] ) for a set of 2D pixels. This is usually used in visual servoing applications to command a robot to move at desired pixel locations/velocities. By inverting this matrix, one can estimate camera spatial velocity i.e., the twist.
Compute the camera twist from a set of 2D pixel locations, their velocities, depth values and intrinsic parameters of the camera. The pixel velocities are usually obtained from optical flow algorithms, both dense and sparse flow can be used to compute the flow between images and duv computed by dividing the flow by the time interval between the images.