From f94f777f0a45894d916bd92e9277f8d6a4053446 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Fri, 1 Nov 2024 20:40:55 +0000 Subject: [PATCH] dlr: make cv2 import optional --- aimodel/src/deeplabv3_plus_test_rainfall.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aimodel/src/deeplabv3_plus_test_rainfall.py b/aimodel/src/deeplabv3_plus_test_rainfall.py index 659a844..eeb472c 100755 --- a/aimodel/src/deeplabv3_plus_test_rainfall.py +++ b/aimodel/src/deeplabv3_plus_test_rainfall.py @@ -12,7 +12,7 @@ import os import io import math import json -import cv2 +# import cv2 # optional import below in get_overlay import numpy as np from glob import glob from scipy.io import loadmat @@ -325,6 +325,10 @@ def decode_segmentation_masks(mask, colormap, n_classes): def get_overlay(image, coloured_mask): + global cv2 + # import cv2 only when used, since it might not be available and this function isn't currently used (was prob something I dropped halfway through writing 'cause I got distracted) + if not cv2: + cv2 = __import__("cv2") image = tf.keras.preprocessing.image.array_to_img(image) image = np.array(image).astype(np.uint8) overlay = cv2.addWeighted(image, 0.35, coloured_mask, 0.65, 0)