Files
supervision/test/detection/test_polygon_zone_annotator.py
T
09de0f4f06 feat(ruff): add pytest linting rule (#2053)
* feat(ruff): add pytest linting rule
* --unsafe-fixes
* fix(pre_commit): 🎨 auto format pre-commit hooks


---------

Co-authored-by: jiri BOROVEC <jirka@Jiris-MacBook-Pro-J4N257Y6Q2.local>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
2026-01-13 19:34:22 +01:00

61 lines
1.6 KiB
Python

import numpy as np
import pytest
import supervision as sv
COLOR = sv.Color(r=255, g=0, b=0)
THICKNESS = 2
POLYGON = np.array([[100, 100], [200, 100], [200, 200], [100, 200]])
SCENE = np.random.randint(0, 255, (1000, 1000, 3), dtype=np.uint8)
ANNOTATED_SCENE_NO_OPACITY = sv.draw_polygon(
scene=SCENE.copy(),
polygon=POLYGON,
color=COLOR,
thickness=THICKNESS,
)
ANNOTATED_SCENE_0_5_OPACITY = sv.draw_filled_polygon(
scene=ANNOTATED_SCENE_NO_OPACITY.copy(),
polygon=POLYGON,
color=COLOR,
opacity=0.5,
)
@pytest.mark.parametrize(
("scene", "polygon_zone_annotator", "expected_results"),
[
(
SCENE,
sv.PolygonZoneAnnotator(
zone=sv.PolygonZone(
POLYGON,
),
color=COLOR,
thickness=THICKNESS,
display_in_zone_count=False,
),
ANNOTATED_SCENE_NO_OPACITY,
), # Test no opacity (default)
(
SCENE,
sv.PolygonZoneAnnotator(
zone=sv.PolygonZone(
POLYGON,
),
color=COLOR,
thickness=THICKNESS,
display_in_zone_count=False,
opacity=0.5,
),
ANNOTATED_SCENE_0_5_OPACITY,
), # Test 10% opacity
],
)
def test_polygon_zone_annotator(
scene: np.ndarray,
polygon_zone_annotator: sv.PolygonZoneAnnotator,
expected_results: np.ndarray,
) -> None:
annotated_scene = polygon_zone_annotator.annotate(scene=scene)
assert np.all(annotated_scene == expected_results)