OpenCV is a widely used computer vision library that provides implementations of many image processing and computer vision algorithms. When developing and using OpenCV applications, it is important to know which OpenCV version you are using. This article will introduce how to check the OpenCV version in Python and provide corresponding source code examples.
In Python, we can use thecv2
module to access the OpenCV library. To check the version of OpenCV we can use the cv2.__version__
attribute. Here is a simple example code:
import cv2
print("OpenCV版本:", cv2.__version__)
Running the above code will output OpenCV version information similar to the following:
OpenCV版本: 4.5.1
By checking the output version information, we can determine the OpenCV version being used. If OpenCV is not installed or the module cannot be imported, an exception will be thrown. In this case, you need to make sure that OpenCV is installed correctly and that Python can find the OpenCV libraries. cv2
ModuleNotFoundError
In addition to directly outputting version information, we can also analyze the version information in more detail. Below is a sample code that will Open