[BENCHAMRK_APP/PYTHON] CV2 module required only when loading images (#13113)

This commit is contained in:
Piotr Krzemiński 2022-10-05 09:50:55 +02:00 committed by GitHub
parent 1bb15b1d18
commit 29a15e39da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0
import os
import cv2
import re
import numpy as np
from collections import defaultdict
@ -126,7 +125,17 @@ def get_input_data(paths_to_input, app_input_info):
return DataQueue(data, get_group_batch_sizes(app_input_info))
def get_image_tensors(image_paths, info, batch_sizes):
def get_image_tensors(image_paths, info, batch_sizes):
try:
import cv2
except ModuleNotFoundError as ex:
raise Exception("Loading images requires the opencv-python or opencv-python-headless package. " \
"Please install it before continuing or run benchmark without "\
"the -i flag to fill vectors with random data.") from ex
except ImportError as ex:
raise Exception("Failed to import opencv module. Please try to uninstall opencv-python " \
"and install opencv-python-headless instead.") from ex
processed_frames = 0
widthes = info.widthes if info.is_dynamic else [info.width]
heights = info.heights if info.is_dynamic else [info.height]