fix(detection): support float64 and arbitrary dtypes in polygon utilities - #2542
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2542 +/- ##
=======================================
Coverage 88% 88%
=======================================
Files 85 85
Lines 12198 12208 +10
=======================================
+ Hits 10734 10744 +10
Misses 1464 1464 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Absolute float32 conversion corrupts large-coordinate polygons, and the required changelog entry is missing.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds broader NumPy dtype support to polygon area filtering and approximation.
Changes:
- Converts unsupported OpenCV dtypes while preserving returned dtypes.
- Adds parametrized dtype tests.
- Fixes the
arestypo.
Review: Code quality 2/5; testing 3/5; documentation 2/5; risk 3/5. Large-coordinate precision and changelog issues remain.
File summaries
| File | Description |
|---|---|
src/supervision/detection/utils/polygons.py |
Adds dtype conversion for OpenCV polygon operations. |
tests/detection/utils/test_polygons.py |
Tests supported input and output dtypes. |
Review details
Suppressed comments (1)
tests/detection/utils/test_polygons.py:188
- Repository test guidance requires non-primitive parametrized cases such as dtype classes to use
pytest.param(..., id="semantic-slug")rather than bare values (.github/CONTRIBUTING.md:342). Use explicit IDs here as well so parametrized case names remain stable and clear.
[np.float64, np.float32, np.int64, np.int32, np.int16, np.uint8],
- Files reviewed: 2/2 changed files
- Comments generated: 4
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Changes: - Rebase polygon coordinates before OpenCV conversion and restore approximated integer coordinates with overflow-safe arithmetic. - Add int64/float64 large-origin regressions, stable dtype parameter IDs, and an Unreleased changelog entry. Impact: - Area filtering and polygon approximation retain small local geometry at large absolute coordinates instead of collapsing float32 deltas. - Tests have readable stable case IDs and the user-visible correction is documented. Verification: - `uv run pytest -q`: 3840 passed, 1 skipped. - Ruff lint and format checks passed; `git diff --check` passed. Residual limits: - Local mypy is unavailable; independent review provenance and Codemap context remain outstanding. --- Co-authored-by: Codex <codex@openai.com>
Borda
approved these changes
Sep 7, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Before submitting
Description
Support arbitrary polygon dtypes (such as
np.float64, NumPy's default float, as well asint64,int16,uint8) infilter_polygons_by_areaandapproximate_polygon.Type of Change
Motivation and Context
cv2.contourAreaandcv2.approxPolyDPrequire inputs of depthCV_32F(np.float32) orCV_32S(np.int32). When users pass standard NumPy polygons (which default tonp.float64ornp.int64on 64-bit systems), OpenCV throws a C++ assertion failure:In addition,
filter_polygons_by_areahad a minor typo referencingaresinstead ofareas.Changes Made
filter_polygons_by_area, passnp.float32copy tocv2.contourAreaif the input polygon is notfloat32orint32. Fixed typoares->areas.approximate_polygon, ensure OpenCV receivesfloat32/int32, while preserving and returning points with the input array's original dtype.tests/detection/utils/test_polygons.pyvalidating behavior acrossnp.float64,np.float32,np.int64,np.int32,np.int16, andnp.uint8.Testing
tests/detection/utils/test_polygons.py)ruff checkandruff format --checkpassed