How to Check OpenCV Version in Python
Last Updated :
25 Apr, 2024
OpenCV (Open Source Computer Vision Library) is a powerful library for computer vision and image processing tasks. Whether you're a beginner or an experienced developer, knowing how to check the version of OpenCV you're using can be essential for compatibility and troubleshooting. In this article, we'll explore different methods to check your OpenCV version using Python.
Check the OpenCV Version in Python
Below, are the methods of Checking your OpenCV version using Python:
- Using cv2.__version__()
- Using cv2.getBuildInformation()
- Using pkg_resources
Check Your OpenCV Version Using cv2.__version__()
The simplest way to check the OpenCV version is by using the cv2.version attribute. This method returns a string representing the OpenCV version. When you run this code snippet, it will print the version of OpenCV installed on your system.
Python3
import cv2
print("OpenCV version:", cv2.__version__)
Output
OpenCV version: 4.9.0
Check Your OpenCV Version Using cv2.getBuildInformation()
Another method to get detailed information about your OpenCV installation is by using cv2.getBuildInformation(). This method provides a comprehensive report containing various details like compiler information, modules enabled, and version.
Python3
import cv2
build_info = cv2.getBuildInformation()
print("OpenCV build information:")
print(build_info)
Output
OpenCV build information:
General configuration for OpenCV 4.9.0 =====================================
Version control: 4.9.0
The output will give you a detailed overview of your OpenCV installation, which can be helpful for debugging or ensuring you have all the required modules enabled.
Check Your OpenCV Version Using pkg_resources
If you've installed OpenCV using pip, you can use pkg_resources to check the version programmatically. This method is particularly useful if you want to verify the version in a more dynamic way.
Python3
import pkg_resources
installed_packages = pkg_resources.working_set
opencv_version = [
pkg for pkg in installed_packages if pkg.key == 'opencv-python'][0].version
print("OpenCV version (via pkg_resources):", opencv_version)
Output
import pkg_resources
OpenCV version (via pkg_resources): 4.9.0.80
This code snippet fetches the version of the 'Opencv-Python' package from the installed packages and prints it out.
Similar Reads
How to check Python Version : Windows, Linux and Mac Python has multiple versions, and it's important to know which version is installed on your system. This information is crucial because different Python versions may have variations in syntax or libraries, and ensuring you're using the correct version is vital for compatibility with your projects. I
5 min read
How to check NumPy version installed? In this article, we are going to learn how we can find out which version of NumPy your Python code uses. The version of any project keeps on changing with time as the project gets updated, new features keep being added, and old bugs are removed. Hence, a lot of work keeps on happening on projects es
2 min read
How to Check PyYAML Version Python Programming Language has various libraries and packages for making tasks easier and more efficient. One such library is PyYAML, which is widely used for parsing and writing YAML, a human-readable data serialization standard. In this article, we will see different methods to check the PyYAML v
3 min read
How to Install OpenCV Python Headless? OpenCV (Open Source Computer Vision Library) is a powerful open-source computer vision and machine learning software library. It enables developers to access a wide range of algorithms for various computer vision tasks. In this article, we will see how to install OpenCV Python Headless. What is Open
2 min read
How to install OpenCV Contrib Python OpenCV (Open Source Computer Vision Library) is a powerful open-source computer vision and machine learning software library. It provides various tools and algorithms for image and video processing, object detection, feature extraction, and more. OpenCV Contrib is an extension module that includes a
2 min read