blob: 254eba63f83e0a49c952cf591ce081ca32a87085 [file] [log] [blame]
Éanna Ó Catháin145c88f2020-11-16 14:12:11 +00001# Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
2# SPDX-License-Identifier: MIT
3
4import os
Raviv Shalev97ddc062021-12-07 15:18:09 +02005import time
Éanna Ó Catháin145c88f2020-11-16 14:12:11 +00006
Raviv Shalev97ddc062021-12-07 15:18:09 +02007import cv2
8import numpy as np
Éanna Ó Catháin145c88f2020-11-16 14:12:11 +00009from context import cv_utils
10from context import utils
Raviv Shalev97ddc062021-12-07 15:18:09 +020011from utils import Profiling
Éanna Ó Catháin145c88f2020-11-16 14:12:11 +000012
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
Raviv Shalev97ddc062021-12-07 15:18:09 +020024
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