Add anchor check and tests to polygon zone

This commit is contained in:
LinasKo 2024-05-28 15:12:48 +03:00
parent c0486b7f94
commit d59467b4f4
3 changed files with 20 additions and 2 deletions

View File

@ -82,8 +82,8 @@ class LineZone:
self.tracker_state: Dict[str, bool] = {}
self.in_count: int = 0
self.out_count: int = 0
self.triggering_anchors = list(triggering_anchors)
if not self.triggering_anchors:
self.triggering_anchors = triggering_anchors
if not list(self.triggering_anchors):
raise ValueError("Triggering anchors cannot be empty.")
@staticmethod

View File

@ -54,6 +54,8 @@ class PolygonZone:
self.polygon = polygon.astype(int)
self.triggering_anchors = triggering_anchors
if not list(self.triggering_anchors):
raise ValueError("Triggering anchors cannot be empty.")
self.current_count = 0

View File

@ -92,3 +92,19 @@ def test_polygon_zone_trigger(
with exception:
in_zone = polygon_zone.trigger(detections)
assert np.all(in_zone == expected_results)
@pytest.mark.parametrize(
"polygon, triggering_anchors, exception",
[
(POLYGON, [sv.Position.CENTER], DoesNotRaise()),
(
POLYGON,
[],
pytest.raises(ValueError),
),
],
)
def test_polygon_zone_initialization(polygon, triggering_anchors, exception):
with exception:
sv.PolygonZone(polygon, FRAME_RESOLUTION, triggering_anchors=triggering_anchors)