1# Copyright © 2020 Arm Ltd and Contributors. All rights reserved. 2# SPDX-License-Identifier: MIT 3 4import os 5import time 6 7import cv2 8import numpy as np 9from context import cv_utils 10from context import utils 11from utils import Profiling 12 13 14def test_get_source_encoding(test_data_folder): 15 video_file = os.path.join(test_data_folder, "Megamind.avi") 16 video, video_writer, frame_count = cv_utils.init_video_file_capture(video_file, "/tmp") 17 assert cv_utils.get_source_encoding_int(video) == 1145656920 18 19 20def test_read_existing_labels_file(test_data_folder): 21 label_file = os.path.join(test_data_folder, "labelmap.txt") 22 labels_map = utils.dict_labels(label_file) 23 assert labels_map is not None 24 25 26def test_preprocess(test_data_folder): 27 content_image = "messi5.jpg" 28 target_shape = (1, 256, 256, 3) 29 padding = True 30 image = cv2.imread(os.path.join(test_data_folder, content_image)) 31 image = cv_utils.preprocess(image, np.float32, target_shape, True, padding) 32 33 assert image.shape == target_shape 34 35 36def test_profiling(): 37 profiler = Profiling(True) 38 profiler.profiling_start() 39 time.sleep(1) 40 period = profiler.profiling_stop_and_print_us("Sleep for 1 second") 41 assert (1_000_000 < period < 1_002_000) 42 43