64

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 ?

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.

1
  • 1
    Open Python IDLE and type following codes import cv2 print cv2.__version__ Feb 3, 2019 at 12:55

5 Answers 5

165

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

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

 dpkg -l | grep libopencv

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

 pkg-config --modversion opencv
1
  • 24
    "pkg-config --modversion opencv" works Apr 10, 2017 at 10:53
64

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

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:

4
  • 7
    If you don't have the development packages installed, you won't have the .pc files and will get an error like Package opencv was not found in the pkg-config search path, which defaults to /usr/lib/pkgconfig/ The --modversion argument is also more helpful for this particular question, as I note below.
    – nealmcb
    Sep 21, 2012 at 18:49
  • 9
    The link you posted has a much better answer now: "pkg-config --modversion opencv" .Thank you for posting
    – I L
    Sep 6, 2016 at 23:39
  • 1
    It worked for me like that in C++ : cout<<"OpenCV Version used:"<<CV_MAJOR_VERSION<<"."<<CV_MINOR_VERSION<<endl;
    – desmond13
    Nov 22, 2016 at 18:01
  • command I do on Debian buster 10 to check openCV version : $ sudo python3 -c "import cv2; print(cv2.__version__)" 4.2.0 Jun 24, 2020 at 12:36
17

1) Direct Answer: Try this:

   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:

"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).

Edit: the reason this questions seems to arise often for OpenCV as 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.

2
  • 1
    cat $(locate OpenCVConfig.cmake) | grep "SET(OpenCV_VERSION "
    – Alan Samet
    Jul 10, 2019 at 1:45
  • @AlanSamet comment is a perfect direct answer Oct 25, 2020 at 13:42
6

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

2

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

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.

With

# dpkg -L libcv2

you can check where are installed

This operative is used for all debian packages.

1
  • Dpkg is spelled wrong here, and those packages aren't in Ubuntu 12.04, so I added a different answer for the latest release.
    – nealmcb
    Sep 21, 2012 at 18:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.