9194ef5abd
Docs/Test Workflow / Test docs build (push) Failing after 0s
Check links & references / links-check (push) Failing after 1s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.10) (push) Failing after 0s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.11) (push) Failing after 0s
PR Conflict Labeler / main (push) Failing after 2s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.12) (push) Failing after 2s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.13) (push) Failing after 0s
Pytest/Test Workflow / Build this Package (push) Failing after 5s
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.10) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.11) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.12) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.13) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.10) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.11) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.12) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.13) (push) Has been cancelled
Pytest/Test Workflow / testing-guardian (push) Has been cancelled
61 lines
1.6 KiB
Python
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)
|