Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

hi pheips,

the info() method is implemented with the help of the CV_INIT_ALGORITHM macro.

so, if you want to build a class on top of Algorithm outside the opencv libs , i.e. within your own codebase, you have to redefine that macro, since it's pretty hard to access otherwise:

#define CV_INIT_ALGORITHM(classname, algname, memberinit) \
    static inline ::cv::Algorithm* create##classname##_hidden() \
    { \
        return new classname; \
    } \
    \
    static inline ::cv::Ptr< ::cv::Algorithm> create##classname##_ptr_hidden() \
    { \
        return ::cv::makePtr<classname>(); \
    } \
    \
    static inline ::cv::AlgorithmInfo& classname##_info() \
    { \
        static ::cv::AlgorithmInfo classname##_info_var(algname, create##classname##_hidden); \
        return classname##_info_var; \
    } \
    \
    static ::cv::AlgorithmInfo& classname##_info_auto = classname##_info(); \
    \
    ::cv::AlgorithmInfo* classname::info() const \
    { \
        static volatile bool initialized = false; \
        \
        if( !initialized ) \
        { \
            initialized = true; \
            classname obj; \
            memberinit; \
        } \
        return &classname##_info(); \
    }

the next step would be to call that macro (after your class definition), and add the member vars you want to get exposed via get/set or serialized via FileStorage:

CV_INIT_ALGORITHM(MyAlgorithm, "MyAlgorithm", // <-- keyword for Algorithm::create()
                  obj.info()->addParam(obj, "aMem ", obj.aMem ,false,0,0,"a nifty comment on aMem");
//                  obj.info()->addParam(obj, "bMem", obj.bMem,false,0,0);
//                  obj.info()->addParam(obj, "cMem", obj.cMem,false,0,0) // note: no ; for the last elem
                      );

hi pheips,

the info() method is implemented with the help of the CV_INIT_ALGORITHM macro.

so, if you want to build a class on top of Algorithm outside the opencv libs , i.e. within your own codebase, you have to redefine that macro, since it's pretty hard to access otherwise:

the 2.4 version:

#define CV_INIT_ALGORITHM(classname, algname, memberinit) \
    static ::cv::Algorithm* create##classname() \
    { \
        return new classname; \
    } \
    \
    static ::cv::AlgorithmInfo& classname##_info() \
    { \
        static ::cv::AlgorithmInfo classname##_info_var(algname, create##classname); \
        return classname##_info_var; \
    } \
    \
    static ::cv::AlgorithmInfo& classname##_info_auto = classname##_info(); \
    \
    ::cv::AlgorithmInfo* classname::info() const \
    { \
        static volatile bool initialized = false; \
        \
        if( !initialized ) \
        { \
            initialized = true; \
            classname obj; \
            memberinit; \
        } \
        return &classname##_info(); \
    }

the 3.0 version:

#define CV_INIT_ALGORITHM(classname, algname, memberinit) \
    static inline ::cv::Algorithm* create##classname##_hidden() \
    { \
        return new classname; \
    } \
    \
    static inline ::cv::Ptr< ::cv::Algorithm> create##classname##_ptr_hidden() \
    { \
        return ::cv::makePtr<classname>(); \
    } \
    \
    static inline ::cv::AlgorithmInfo& classname##_info() \
    { \
        static ::cv::AlgorithmInfo classname##_info_var(algname, create##classname##_hidden); \
        return classname##_info_var; \
    } \
    \
    static ::cv::AlgorithmInfo& classname##_info_auto = classname##_info(); \
    \
    ::cv::AlgorithmInfo* classname::info() const \
    { \
        static volatile bool initialized = false; \
        \
        if( !initialized ) \
        { \
            initialized = true; \
            classname obj; \
            memberinit; \
        } \
        return &classname##_info(); \
    }

the next step would be to call that macro (after your class definition), and add the member vars you want to get exposed via get/set or serialized via FileStorage:

CV_INIT_ALGORITHM(MyAlgorithm, "MyAlgorithm", // <-- keyword for Algorithm::create()
                  obj.info()->addParam(obj, "aMem ", obj.aMem ,false,0,0,"a nifty comment on aMem");
//                  obj.info()->addParam(obj, "bMem", obj.bMem,false,0,0);
//                  obj.info()->addParam(obj, "cMem", obj.cMem,false,0,0) // note: no ; for the last elem
                      );