Ask Your Question

How To Safely Use OpenCV 2.4.7 and OpenCV 3.0.0 In Same Project?

asked 2013-12-17 13:05:02 -0600

trianta2 gravatar image

updated 2013-12-17 13:33:37 -0600

Language: C++
OS : Linux (Ubuntu)

Hi Everyone,

I'm developing a program where I need to use both OpenCV 2.4.7 and OpenCV 3.0.0 in the same project. I need OpenCV 2.4.7 due to legacy dependencies that a framework I'm using has, and I need OpenCV 3.0.0 for the HDR fusion library. There is no way that I can split the framework and the HDR fusion class/library apart into separate projects.

I've been having problems using both libraries together, as one would expect. At first, OpenCV 3.0.0's header files were actually pointing at OpenCV 2.4.7's header files. I fixed this by appending a "_" character on the OpenCV 3.0.0 folder, so now I can differentiate 2.4.7 from 3.0.0 by using #include <opencv2/...> vs. #include <opencv2_/>, respectively.

I have a new problem that I'm not sure how to solve. When I try to compile my code, I get errors about undeclared variables and such. I believe that there is a namespace conflict, and/or perhaps I've entered DLL hell.

/usr/local/include/opencv2_/imgproc.hpp:637: error: 'BORDER_REPLICATE' was not declared in this scope

/usr/local/include/opencv2_/imgproc.hpp:988: error: 'BORDER_DEFAULT' was not declared in this scope

/usr/local/include/opencv2_/imgproc.hpp:1049: error: 'BORDER_CONSTANT' was not declared in this scope

Note that I have successfully compiled and run a test project that only uses the HDR library in OpenCV 3.0.0, so I know that it works standalone.

Has anyone been able to successfully use different versions of OpenCV in the same project? If so I'd really appreciate hearing about it.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-12-18 01:35:45 -0600

OpenCV library is binary compatible inside 2.4 branch, so you can exchange library and use several impls of OpenCV. But OpenCV 3.0.0 from master is binary incompatible with 2.4.x branch. It means that cv::Mat and other data types can have and actually have different memory layout. So, you cannot pass cv::Mat from 2.4.x to 3.0.0. I recommend you to port your legacy code on 3.0.0. From my poit of view it is easier then integrate to different library versions.

edit flag offensive delete link more


As Alternative you can try to back port HDR module on base of 2.4 branch.

Alexander Smorkalov gravatar imageAlexander Smorkalov ( 2013-12-18 01:49:28 -0600 )edit

Question Tools


Asked: 2013-12-17 13:05:02 -0600

Seen: 791 times

Last updated: Dec 18 '13