Python: Getting OpenCV version

In this short tutorial, we will check how to obtain the version of the Python OpenCV module we have installed in our machine.

Introduction

In this short tutorial, we will check how to obtain the version of the Python OpenCV module we have installed in our machine.

We will do it by writing a very simple Python script which will import the module and then access its__version__ attribute. You can read more about this attribute here.

Being able to obtain the OpenCV version installed might be important, for example, to confirm that we have access to a certain feature that is not implemented in older versions.

The code shown below was tested using Python v3.7.2, on Windows 8.1.

The code

As already mentioned, we will obtain the version of the OpenCV module using a very simple script. The first thing we will do is importing the cv2 module.

import cv2

Then, we will print the value of the __version__ attribute of the module. This should output the OpenCV version.

print(cv2.__version__)

The final script can be seen below.

import cv2
 
print(cv2.__version__)

Testing the code

To test the code, simply run it on an environment of your choice. In my case I’ll be using IDLE, a Python IDE. Note that I’m assuming you have the OpenCV module installed.

You should get an output similar to figure 1. As can be seen, the image shows the version of my OpenCV installation. In my case, I have version 4.0.0.

Naturally, depending on the version you have installed on your machine, the actual version printed might differ.

Obtaining Python OpenCV version installed.
Figure 1 – Output of the script to get the version of OpenCV installed.

Related Posts

Leave a Reply