Éanna Ó Catháin | 145c88f | 2020-11-16 14:12:11 +0000 | [diff] [blame] | 1 | # Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | |
| 4 | import os |
Raviv Shalev | 97ddc06 | 2021-12-07 15:18:09 +0200 | [diff] [blame] | 5 | import time |
Éanna Ó Catháin | 145c88f | 2020-11-16 14:12:11 +0000 | [diff] [blame] | 6 | |
Raviv Shalev | 97ddc06 | 2021-12-07 15:18:09 +0200 | [diff] [blame] | 7 | import cv2 |
| 8 | import numpy as np |
Éanna Ó Catháin | 145c88f | 2020-11-16 14:12:11 +0000 | [diff] [blame] | 9 | from context import cv_utils |
| 10 | from context import utils |
Raviv Shalev | 97ddc06 | 2021-12-07 15:18:09 +0200 | [diff] [blame] | 11 | from utils import Profiling |
Éanna Ó Catháin | 145c88f | 2020-11-16 14:12:11 +0000 | [diff] [blame] | 12 | |
| 13 | |
| 14 | def 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 | |
| 20 | def 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 Shalev | 97ddc06 | 2021-12-07 15:18:09 +0200 | [diff] [blame] | 24 | |
| 25 | |
| 26 | def 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 | |
| 36 | def 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 | |