C++ 如何确定 OpenCV 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11030640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to determine OpenCV version
提问by penelope
How to determine which version of OpenCV I have installed?
如何确定我安装了哪个版本的 OpenCV?
I am most interested in knowing a way of doing it programatically (and cross-platform), but I can't even find a way to determine the installed version from outside the code.
我最想知道一种以编程方式(和跨平台)进行操作的方法,但我什至找不到从代码外部确定已安装版本的方法。
I'm working with C++03, on Fedora.
我正在 Fedora 上使用 C++03。
回答by juanchopanza
You can check the CV_VERSION
macro.
你可以检查CV_VERSION
宏。
回答by CharlesB
You can check the following macro variables:
您可以检查以下宏变量:
CV_MAJOR_VERSION
CV_MINOR_VERSION
回答by Martin R.
If you also want to get build information, you can use this code:
如果您还想获取构建信息,可以使用以下代码:
printf("OpenCV: %s", cv::getBuildInformation().c_str());
回答by user1270710
The version string is located in:
版本字符串位于:
https://github.com/opencv/opencv/blob/master/modules/core/include/opencv2/core/version.hpp
https://github.com/opencv/opencv/blob/master/modules/core/include/opencv2/core/version.hpp
Top of version.hpp, below the BSD license:
#define CV_VERSION_MAJOR 3
#define CV_VERSION_MINOR 2
#define CV_VERSION_REVISION 0
回答by T.Chia
pkg-config --modversion opencv
pkg-config --modversion opencv
回答by David St?elák
I would like to enhance one of the answers using version.hpp defines.
我想使用 version.hpp 定义来增强答案之一。
Please notice the potential problem with that solution:
请注意该解决方案的潜在问题:
v. 2.4.13.6 defines:
v. 2.4.13.6 定义:
#define CV_VERSION_EPOCH 2
#define CV_VERSION_MAJOR 4
#define CV_VERSION_MINOR 13
#define CV_VERSION_REVISION 6
#if CV_VERSION_REVISION
# define CV_VERSION CVAUX_STR(CV_VERSION_EPOCH) "." CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR) "." CVAUX_STR(CV_VERSION_REVISION)
#else
# define CV_VERSION CVAUX_STR(CV_VERSION_EPOCH) "." CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR)
#endif
and v. 3.4.2 defines:
和 v. 3.4.2 定义:
#define CV_VERSION_MAJOR 3
#define CV_VERSION_MINOR 4
#define CV_VERSION_REVISION 2
#define CV_VERSION CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR) "." CVAUX_STR(CV_VERSION_REVISION) CV_VERSION_STATUS
As a result, CV_VERSION_MAJORare not comparable. Much safer solution is to parse CV_VERSIONand use the first value before a dot.
因此,CV_VERSION_MAJOR没有可比性。更安全的解决方案是解析 CV_VERSION并使用点之前的第一个值。
回答by Eric
If you install from svn repository, you can see the exact revision version like that:
如果您从 svn 存储库安装,您可以看到如下所示的确切修订版本:
#?in the opencv.svn directory
svn info
回答by jihed gasmi
if you are working under Windows and you need to configure Codeblocks or any other IDE (thus,you can not issue any command yet nor compile a program ) you can simply go to the folder of installation of OpenCV and look after the final leters of the libraries in the sub-folder "/lib" .All libraries there are named in a pattern that reflects the major,minor and the revision of the build of OpenCV.For instance if you stumble upon a file named opencv_ts300.libor opencv_world300.libthen the major is 3,minor is 0 and revision is 0.
如果您在 Windows 下工作并且需要配置 Codeblocks 或任何其他 IDE(因此,您还不能发出任何命令,也不能编译程序),您可以简单地转到 OpenCV 的安装文件夹并查看最后的字母子文件夹“/lib”中的库。所有库都以反映主要、次要和 OpenCV 构建版本的模式命名。例如,如果您偶然发现名为opencv_ts300.lib或opencv_world300.lib的文件那么主要是3,次要是0,修订是0。
(Note: it's likely that this method fails I mean when these informations do not comply with the real version but this will be maybe with the revision but unlikely with the major)
(注意:这种方法很可能会失败,我的意思是当这些信息与真实版本不符时,这可能与修订版有关,但在专业版中不太可能)