Tracker Factory and Command Line Arguments - asolis/vivaTracker GitHub Wiki

Step 3: Tracker Factory and Command Line Arguments.

As the final steps we should include our NCCTracker implementation to the vivaTracker tracker's factory. This will allow the framework to generate new instances of our defined class and define the command line options that it will support.

First, we need to include our header file containing the NCCTracker to the factories.h header inside of the trackerlib.

contents of factories.h file:
...
#ifdef WITH_NCC   <-- Add a new include containing the NCCTracker declaration if WITH_NCC is defined. 
#include "ncc.h"
#endif            
...

Then, we should modify the createTracker method inside factories.cpp file by adding the options to create an instance of NCCTracker.

This method is called by the vivaTracker project from the command line to create instances of the specified method (e.g., skcf, ncc, kcf, opentld, etc..).

Note: the method name should be the same of the folder containing the created tracker in the Step 1. In our example of NCCTracker the folder is ncc.

factories.cpp content
  Ptr<Tracker> TrackerFactory::createTracker(const string &method, const int argc, const char * argue[])
  {
    Ptr<Tracker> tracker;
    ...
#ifdef WITH_NCC
    if (method == "ncc") // if the selected method is ncc, we should return a pointer to NCCTracker
    {
        //Default command line options for the new tracker
        const String keys =
        "{? usage           |       | print this message}";
        
        //Passing the command line to the OpenCV 3.x command line parser
        CommandLineParser parser(argc, argv, keys);
        
        //Creating a new instance of our tracker
        //We should process any command line argument and passed to our implementation 
        //when needed
        tracker = new NCCTracker();
        
        //If the help option was one for the current tracker implementation
        //Return an empty tracker and print help message plus algorithm description. 
        if (parser.has("?"))
        {
            parser.about(tracker->getDescription());
            parser.printMessage();
            return Ptr<Tracker>();
        }
    }
#endif
    ...
}

Finally, our tracker is already in place and can be used with any sequence. For example:

./vivaTracker -m=ncc vot2013/bolt 
⚠️ **GitHub.com Fallback** ⚠️