Does OpenCv have a constant with its version number?

c++, opencv, shared-libraries

Solution

In addition to great @berak's answer (related to version.hpp):

There are different naming schemes in OpenCV 2.4 and OpenCV 3.0 branches. For OpenCV 2.4.x we have something like this (note that for 2.4.x `CV_VERSION_MAJOR` is 4):

#define CV_VERSION_EPOCH    2
#define CV_VERSION_MAJOR    4
#define CV_VERSION_MINOR    8
#define CV_VERSION_REVISION 0

And for OpenCV 3.0.x we have the following (note that `CV_VERSION_MAJOR` sense was changed!):

#define CV_VERSION_MAJOR    3
#define CV_VERSION_MINOR    0
#define CV_VERSION_REVISION 0
#define CV_VERSION_STATUS   "-dev"

That is if you need support for both 2.4.x abd 3.0.x, code will be slightly non-obvious if you want to check `CV_VERSION_MAJOR`. I prefer checking `CV_VERSION_EPOCH` instead:

#if (defined(CV_VERSION_EPOCH) && CV_VERSION_EPOCH == 2)
# OpenCV 2.4.x stuff
#else
# OpenCV 3.0 stuff
#endif

Problem

I ask this because I have a couple installed and have some doubts if I am loading the right dynamic libraries. This question is slightly different from these as they answer what is installed and not what your application is linking: Find OpenCV Version Installed on Ubuntu How to check for openCV

Original source

Related problems