C++ 查找 Ubuntu 上安装的 OpenCV 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8804064/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 19:08:07  来源:igfitidea点击:

Find OpenCV Version Installed on Ubuntu

c++opencv

提问by Saad

I would like to find out what version of OpenCV is installed on my computer (i am running Ubuntu 10.04). Is there a simple way to check it if ? If not then can i find out the directories where files (samples, etc) are installed ?

我想知道我的计算机上安装了哪个版本的 OpenCV(我运行的是 Ubuntu 10.04)。有没有简单的方法来检查它是否?如果没有,那么我可以找出安装文件(样本等)的目录吗?

I am trying to run some code that i have already tested on another computer with OpenCV 2.3 installed and i get many errors.

我正在尝试运行一些我已经在另一台安装了 OpenCV 2.3 的计算机上测试过的代码,但出现了很多错误。

回答by nealmcb

The other methods here didn't work for me, so here's what does work in Ubuntu 12.04 'precise'.

这里的其他方法对我不起作用,所以这是在 Ubuntu 12.04“精确”中起作用的方法。

On Ubuntu and other Debian-derived platforms, dpkg is the typical way to get software package versions. For more recent versions than the one that @Tio refers to, use

在 Ubuntu 和其他 Debian 衍生平台上,dpkg 是获取软件包版本的典型方式。对于比@Tio 引用的版本更新的版本,请使用

 dpkg -l | grep libopencv

If you have the development packages installed, like libopencv-core-dev, you'll probably have .pcfiles and can use pkg-config:

如果你安装了开发包,比如libopencv-core-dev,你可能会有.pc文件并且可以使用pkg-config

 pkg-config --modversion opencv

回答by crenate

You can look at the headers or libs installed. pkg-config can tell you where they are:

您可以查看安装的头文件或库。pkg-config 可以告诉你它们在哪里:

pkg-config --cflags opencv
pkg-config --libs opencv

Alternatively you can write a simple program and print the following defs:

或者,您可以编写一个简单的程序并打印以下定义:

CV_MAJOR_VERSION
CV_MINOR_VERSION

A similar question has been also asked here:

这里也有人问类似的问题:

回答by peter karasev

1) Direct Answer: Try this:

1)直接回答:试试这个:

   sudo updatedb
   locate OpenCVConfig.cmake

For me, I get:

对我来说,我得到:

   /home/pkarasev3/source/opencv/build/OpenCVConfig.cmake

To see the version, you can try:

要查看版本,您可以尝试:

   cat /home/pkarasev3/source/opencv/build/OpenCVConfig.cmake

giving

给予

    ....
   SET(OpenCV_VERSION 2.3.1)
    ....

2) Better Answer:

2)更好的答案:

"sudo make install" is your enemy, don't do that when you need to compile/update the library often and possibly debug step through it's internal functions. Notice how my config file is in a local build directory, not in /usr/something. You will avoid this confusion in the future, and can maintain several different versions even (debug and release, for example).

“sudo make install”是你的敌人,当你需要经常编译/更新库并可能调试它的内部函数时,不要这样做。请注意我的配置文件如何在本地构建目录中,而不是在 /usr/something 中。将来您将避免这种混淆,甚至可以维护多个不同的版本(例如调试和发布)。

Edit: the reason this questions seems to arise often for OpenCVas opposed to other libraries is that it changes rather dramatically and fast between versions, and many of the operations are not so well-defined / well-constrained so you can't just rely on it to be a black-box like you do for something like libpng or libjpeg. Thus, better to not install it at all really, but just compile and link to the build folder.

编辑:与其他库相比,OpenCV似乎经常出现这个问题的原因是它在版本之间变化相当大和快速,而且许多操作没有那么明确/约束很好,所以你不能仅仅依赖就像你对 libpng 或 libjpeg 之类的东西所做的一样,它是一个黑匣子。因此,最好不要真正安装它,而只是编译并链接到构建文件夹。

回答by Kevin

There is also a flag CV_VERSION which will print out the full version of opencv

还有一个标志 CV_VERSION 将打印出完整版的 opencv

回答by Tio Pepe

To install this product you can see this tutorial: OpenCV on Ubuntu

要安装此产品,您可以查看本教程:Ubuntu 上的 OpenCV

There are listed the packages you need. So, with:

列出了您需要的软件包。所以,与:

# dpkg -l | grep libcv2
# dpkg -l | grep libhighgui2

and more listed in the url you can find which packages are installed.

以及在 url 中列出的更多信息,您可以找到安装了哪些软件包。

With

# dpkg -L libcv2

you can check where are installed

您可以检查安装位置

This operative is used for all debian packages.

此操作用于所有 debian 软件包。