1 | initial version |
Algorithm is not dead, it's more than alive; the algorithm "by-name" factory is dead because of multiple problems with it - non-guaranteed initialization, modules thrown away by linker, because it did not find any dependency of e.g. SIFT, big space overhead etc.
Well, if you like, do something like this in your code:
typedef Ptr<Algorithm> (*algo_creator_t)();
// proxy functions are needed since SIFT::create() etc. have optional parameters,
// so the function pointers can not be unified.
static Ptr<Algorithm> create_SIFT() { return SIFT::create(); }
static Ptr<Algorithm> create_ORB() { return ORB::create(); }
...
std::map<string, algo_creator_t> factory;
factory["SIFT"] = create_SIFT;
factory["ORB"] = create_ORB;
...
string name = use_orb ? "ORB" : "SIFT";
Ptr<Feature2D> obj = factory[name]().dynamicCast<Feature2D>();