Last active
July 30, 2019 00:48
-
-
Save planetceres/1a9f718e04e2fa3573082def692338d8 to your computer and use it in GitHub Desktop.
OpenCV Version Conditionals
This file contains hidden or 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
# https://www.pyimagesearch.com/2015/08/10/checking-your-opencv-version-using-python/ | |
def is_cv2(): | |
return check_opencv_version("2.") | |
def is_cv3(): | |
return check_opencv_version("3.") | |
def is_cv4(): | |
return check_opencv_version("4.") | |
def check_opencv_version(major, lib=None): | |
if lib is None: | |
import cv2 as lib | |
return lib.__version__.startswith(major) | |
if is_cv2(): | |
print("CV 2") | |
if is_cv3(): | |
print("CV 3") | |
if is_cv4(): | |
print("CV 4") | |
# https://stackoverflow.com/a/54703223 | |
if cv2.check_opencv_version() in [2, 4]: | |
# OpenCV 2, OpenCV 4 | |
contour, hier = cv2.findContours( | |
thresh.copy(), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE) | |
else: | |
# OpenCV 3 | |
image, contour, hier = cv2.findContours( | |
thresh.copy(), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment