-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(detection): add require_all_anchors to PolygonZone #2272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ace3Z
wants to merge
1
commit into
roboflow:develop
Choose a base branch
from
Ace3Z:feat/polygon-zone-require-all-anchors
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,16 @@ def test_empty_anchors_raises(self, polygon, triggering_anchors, exception): | |
| with exception: | ||
| sv.PolygonZone(polygon, triggering_anchors=triggering_anchors) | ||
|
|
||
| def test_generator_triggering_anchors_is_materialized(self): | ||
| """A generator passed for triggering_anchors must not be silently exhausted.""" | ||
| zone = sv.PolygonZone( | ||
| POLYGON, triggering_anchors=(p for p in [sv.Position.CENTER]) | ||
| ) | ||
| detections = _create_detections( | ||
| xyxy=[[140.0, 140.0, 160.0, 160.0]], class_id=[0] | ||
| ) | ||
| assert zone.trigger(detections)[0] | ||
|
|
||
|
|
||
| class TestPolygonZoneTrigger: | ||
| @pytest.mark.parametrize( | ||
|
|
@@ -164,3 +174,21 @@ def test_anchor_on_polygon_boundary_included(self) -> None: | |
| ) | ||
| result = zone.trigger(detections) | ||
| assert result[0] | ||
|
|
||
| def test_require_all_anchors_false_triggers_on_any_anchor(self) -> None: | ||
| """With require_all_anchors=False, any anchor inside triggers.""" | ||
| # Box [85, 85, 115, 115] has only BOTTOM_RIGHT (115, 115) inside POLYGON | ||
| # ([100, 100]..[200, 200]); the other three corners are outside. | ||
| detections = _create_detections(xyxy=[[85.0, 85.0, 115.0, 115.0]], class_id=[0]) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That line measures 86 characters including leading indent, which is under the configured 88-character limit. ruff format also leaves it alone in pre-commit, both locally and in pre-commit.ci on this PR. Looks like a Copilot false positive. |
||
| anchors = ( | ||
| sv.Position.TOP_LEFT, | ||
| sv.Position.TOP_RIGHT, | ||
| sv.Position.BOTTOM_LEFT, | ||
| sv.Position.BOTTOM_RIGHT, | ||
| ) | ||
| all_required = sv.PolygonZone(POLYGON, triggering_anchors=anchors) | ||
| any_anchor = sv.PolygonZone( | ||
| POLYGON, triggering_anchors=anchors, require_all_anchors=False | ||
| ) | ||
| assert not all_required.trigger(detections)[0] | ||
| assert any_anchor.trigger(detections)[0] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Fixed by materializing the iterable once with list(triggering_anchors) at the top of init, and added a regression test that passes a generator and asserts trigger() still works. Pushed in the latest commit.