Mixing opencv 2.4.x and 3.3.x in one application (single process)
Hi, thank you in advance for your help.
I am in a situation where I need to use a library from latest opencv and use it side by side with an older version. So far my attempts have been:
- Change the include paths so that the two don't conflict. That is change all opencv to opencv_3.3.x for the latest version and try static linking. The project builds fine but when it is referenced by a project that uses an older version of opencv, all hell breaks loose and I get all kinds of redefinition errors.
Is it worth the effort to try and run the two side by side. The reason is I need to integrate a deep learning network to a legacy application that uses opencv. The easiest way to do that is to use the latest opencv dnn library.
I'm using Visual Studio 12 with vc11 compiler package.
Thank you -Henok
One way would be to make two wrapper DLLs that act as a buffer between your code and the OpenCV code. That way you can build one version into one DLL, and build the other version into the other DLL. None of your current redefinition problems will occur. Writing a DLL is not very hard -- Visual Studio has a template DLL project even.
Another way would be to write just one DLL, and build one version into it, and then build the other version directly into the exe file. In this case I'd make the DLL encapsulate the newest version of OpenCV, since that's the API that you work the least with (you only have to encapsulate the DNN functionality).
It's your call.
On second thought, this solution might not work at first. I'm using VS Community 2017 (VC19), and I had no problem making the DLL file, but when I add code that uses the OpenCV library, I get linker errors; undefined references.
I put the DLL wrapper code at: https://github.com/sjhalayka/OpenCV3_...
I put the DLL wrapper user code at: https://github.com/sjhalayka/OpenCV3_...
It looks like you might have to also encapsulate the Mat class, or better yet, just pass around the raw image data between the exe (wrapper user) and the DLL (wrapper). I'll play around with it for a bit more to see what I come up with.
Thanks a bunch for your help. What you described above, option 2, is what I'm leaning towards as well. I'll be expecting a cv::Mat or just buffer of pixels from legacy code and do transform\convert to cv::Mat before passing input through network.
Hi again, I fixed the wrapper and wrapper user code. They pass around a vector<float> by reference, to store floating-point image data. You can grab a pointer to the vector's memory block by using the address-of operator
So the Mat constructor (in your OpenCV 2.x code) would be
My GitHub repositories listed above are using option #2.
P.S. If you come up with a solution, write about it as an answer to this question.
Thanks my friend. I'm pretty much using what you have, except I need char* instead of vector<float>. Cross fingers :-( Will close the case for now.
Alright, well let us know if you need help with anything else. It was a fun project to work on. :)