Skip to content

Conversation

Adithi-Sreenath
Copy link

Description

Fixes PolygonZone allowing objects to appear in multiple zones simultaneously.
Resolves #1987

When checking if a detection is inside a polygon zone, the previous implementation would clip the bounding box to fit within each ROI's dimensions before calculating anchor points. This caused the same detection to produce different anchor points for different ROIs, allowing it to be counted as present in multiple zones.

Example:

  • Detection box: [441, 258, 718, 713]
  • ROI1 bounds: [0, 167, 457, 427]
  • ROI2 bounds: [458, 67, 1011, 309]

Before fix:

  • Clipped to ROI1: [441, 258, 457, 427] → anchor at (449, 427) → detected in ROI1 ✗
  • Clipped to ROI2: [458, 258, 718, 309] → anchor at (588, 309) → detected in ROI2 ✗
  • Result: Object counted in BOTH zones

After fix:

  • Original box center: (580, 485)
  • Check against ROI1: center not in ROI1 → False ✓
  • Check against ROI2: center in ROI2 → True ✓
  • Result: Object counted in only ONE zone

Bug visualization

Before Fix

Before fix

After Fix

After fix

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How has this change been tested?

  1. Automated tests: All 6 tests in test/detection/test_polygonzone.py pass:
    • test_polygon_zone_trigger
    • test_polygon_zone_initialization
  2. Manual verification: Ran bug_recreation.py and fix_test.py on a sample image to confirm:
    • Original detection spanning multiple ROIs → previously counted in multiple zones
    • After fix → correctly counted in only one zone

Any specific deployment considerations

  • Only the trigger() method of PolygonZone was modified.
  • No API or interface changes.
  • No secrets or additional dependencies.

Docs

  • Docs updated?
    • Updated docstring of trigger() explaining anchor calculation and bug fix.

when checking if a detection is inside a polygon zone, the previous implementation
would clip the bounding box to fit within each ROI's dimensions before calculating
anchor points. This caused the same detection to produce different anchor points
for different ROIs, allowing it to be counted as present in multiple zones.
@CLAassistant
Copy link

CLAassistant commented Oct 14, 2025

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Polygon Zone Superposition - Clipping bug

2 participants