Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is a solution that worked for me using boost.extension extensiblity library which is long deprecated but had it at my disposal. You can look into Microsoft's COM or Mozilla's XPCOM (Cross-platform COM) as an alternative to boost.extension. Probably better too.

Compiler packages: vc11 visual studio 12  
OS: windows 7 x64  Integration
target: Legacy application with opencv 2.4.5 
New version: opencv 3.3.1 - the dnn module in particular

The end solution was to write a wrapper\extension with network interface. This wraps API in COM server for version 3. The interface defines entry to opencv dnn stuff and is called by the legacy code that uses earlier version of opencv. Notice the interface makes no opencv3 references.

Interface :

// This is the dispatcher that gets statically linked to the legacy code 
class IOpenCV3Interface 
{
public: 
         typedef boost::shared_ptr<IOpenCV3Interface> ptr; // will be used by extension manager to load this class 
         virtual bool Classify(const char* data, const int &width, const int &height)
}

In legacy code we use boost extension manager to instantiate this object and call classify:

IOpencv3Interface::ptr _opencv3Interface = ExtensionFinder<IOpencv3Interface>().CreateSingle()
_opencv3Ingerface.Classify(data,10,10)

at this point a call to opencv 3 is on its way

Now have a derived class implement classify which uses opencv stuff.

//This gets loaded by the dispatcher dynamically using boost.extension manager 
class Classifier : IOpenCV3Interface 
{
            public: 
                 bool Classify(const char* data, const int& w, const int& h) override;
}

clasifier.cpp 
Classifer::Classify(const char* data, const int& w, const int &h)
{
          //use open cv 3. 
}

This approach essentially decouples the two libraries by adding the opencv 3 code as a plugin. Compiler is okay with this so far. I'll update the answer if anything changes

Let me know if you have any questions