Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

if you can live with the generic cv::Tracker interface for the trackers created, you could generate a factory (wrapper) function, so you can store unique function pointers (of the same signature) in your map later:

// map value type
typedef cv::Ptr<cv::Tracker> (*TrackerFactory)();

// generated function sig
template<class T>
cv::Ptr<cv::Tracker> _wrap(){ return T::create(); }

int main()
{
    std::map<std::string, TrackerFactory> trackerTypes_map;
    trackerTypes_map["BOOSTING"] = _wrap<cv::TrackerBoosting>;
    trackerTypes_map["MIL"]      = _wrap<cv::TrackerMIL>;
    trackerTypes_map["MOSSE"]    = _wrap<cv::TrackerMOSSE>;

    auto test = [&](string s){
        cout << s << "\t\t";
        TrackerFactory factory = trackerTypes_map[s]; // returns nullptr for unknown keys
        cout << factory;
        if (factory) { // mandatory check !
            Ptr<Tracker> p1 = factory();
            cout << " " << (!p1.empty());
        }
        cout << endl;
    };
    test("MOSSE");
    test("MIL");
    test("Boostings");
    test("BOOSTING");
}