Created
February 24, 2019 13:42
-
-
Save brionmario/0e15197b8e20c5d9cdc2d8b8fea7c530 to your computer and use it in GitHub Desktop.
This simple util can be used to check the OpenCV version available in the environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
This simple util can be used to check the OpenCV version | |
available in the environment. | |
Usage: | |
Can be used to handle backward compatibility issues across OpenCV versions. | |
""" | |
def is_v2(): | |
""" Checks if the OpenCV version starts with 2. i.e if the major version is 2 | |
Returns: | |
bool: True if the version starts with 2, False otherwise. | |
""" | |
return check_cv_version("2.") | |
def is_v3(): | |
""" Checks if the OpenCV version starts with 3. i.e if the major version is 3 | |
Returns: | |
bool: True if the version starts with 3, False otherwise. | |
""" | |
return check_cv_version("3.") | |
def is_v4(): | |
""" Checks if the OpenCV version starts with 4. i.e if the major version is 4 | |
Returns: | |
bool: True if the version starts with 4, False otherwise. | |
""" | |
return check_cv_version("4.") | |
def check_cv_version(major, lib=None): | |
# if the supplied library is None, import OpenCV | |
if lib is None: | |
import cv2 as lib | |
# return whether or not the current OpenCV version matches the | |
# major version number | |
return lib.__version__.startswith(major) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment