|
1 | 1 | #
|
2 |
| -# Copyright (C) 2020-2024 Intel Corporation |
| 2 | +# Copyright (C) 2024-2025 Intel Corporation |
3 | 3 | # SPDX-License-Identifier: Apache-2.0
|
4 | 4 | #
|
5 | 5 | import numpy as np
|
|
9 | 9 | resize_image_with_aspect_ocv,
|
10 | 10 | )
|
11 | 11 | from openvino.preprocess import PrePostProcessor
|
| 12 | +import cv2 as cv |
| 13 | +import pytest |
12 | 14 |
|
13 | 15 |
|
14 |
| -def test_resize_image_with_aspect_ocv(): |
15 |
| - param_node = ov.op.Parameter(ov.Type.f32, ov.Shape([1, 8, 8, 3])) |
| 16 | +@pytest.mark.parametrize( |
| 17 | + "img_shape", |
| 18 | + [(301, 999, 3), (999, 301, 3), (500, 500, 3), (1024, 768, 3), (768, 1024, 3)], |
| 19 | +) |
| 20 | +def test_resize_image_with_aspect_ocv(img_shape): |
| 21 | + model_h = 1024 |
| 22 | + model_w = 1024 |
| 23 | + pad_value = 0 |
| 24 | + |
| 25 | + param_node = ov.op.Parameter(ov.Type.f32, ov.Shape([1, model_h, model_w, 3])) |
16 | 26 | model = ov.Model(param_node, [param_node])
|
17 | 27 | ppp = PrePostProcessor(model)
|
18 | 28 | ppp.input().tensor().set_element_type(ov.Type.u8)
|
19 | 29 | ppp.input().tensor().set_layout(ov.Layout("NHWC"))
|
20 | 30 | ppp.input().tensor().set_shape([1, -1, -1, 3])
|
21 | 31 | ppp.input().preprocess().custom(
|
22 | 32 | resize_image_with_aspect(
|
23 |
| - (8, 8), |
| 33 | + (model_h, model_w), |
24 | 34 | "linear",
|
25 |
| - 0, |
| 35 | + pad_value, |
26 | 36 | )
|
27 | 37 | )
|
28 | 38 | ppp.input().preprocess().convert_element_type(ov.Type.f32)
|
29 | 39 | ov_resize_image_with_aspect = ov.Core().compile_model(ppp.build(), "CPU")
|
30 | 40 |
|
31 |
| - img = np.ones((2, 4, 3), dtype=np.uint8) |
32 |
| - ov_results = ov_resize_image_with_aspect(img[None]) |
33 |
| - np_results = resize_image_with_aspect_ocv(img, (8, 8)) |
| 41 | + img = np.random.randint(0, 255, size=img_shape, dtype=np.uint8) |
| 42 | + ov_results = list(ov_resize_image_with_aspect(img[None]).values())[0][0] |
| 43 | + |
| 44 | + np_results = resize_image_with_aspect_ocv(img, (model_w, model_h)) |
34 | 45 |
|
35 |
| - assert np.sum(np.abs(list(ov_results.values())[0][0] - np_results)) < 1e-05 |
| 46 | + assert cv.PSNR(np_results.astype(np.float32), ov_results) > 20.0 |
0 commit comments