generated from roboflow/template-python
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathtest_polygon_zone_annotator.py
60 lines (56 loc) · 1.61 KB
/
test_polygon_zone_annotator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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)