Conversation
Co-authored-by: Codex <codex@openai.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #2430 +/- ##
=======================================
- Coverage 87% 86% -0%
=======================================
Files 72 73 +1
Lines 10679 10774 +95
=======================================
+ Hits 9264 9297 +33
- Misses 1415 1477 +62 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a private OpenCV compatibility facade (supervision._cv2) and refactors Supervision’s internal OpenCV usage to route through that single boundary. This centralizes OpenCV symbol imports and enables clearer failure behavior (or limited constant availability) in environments where cv2 cannot be imported.
Changes:
- Added
src/supervision/_cv2/__init__.pyas a curated OpenCV surface with a fallback mode that raisesBackendUnavailableErrorfor operations without an available backend. - Replaced direct
import cv2usage across multiple modules/tests/doc examples withfrom supervision import _cv2 as cv2. - Added a dedicated test suite (
tests/cv2/) to validate the facade’s exported surface, constant alignment, and fallback behavior.
Reviewed changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/utils/test_video.py | Switch test OpenCV import to the _cv2 facade. |
| tests/utils/test_image.py | Switch test OpenCV import to the _cv2 facade. |
| tests/cv2/test_cv2.py | Add tests asserting _cv2 exports/behavior and fallback import scenarios. |
| tests/cv2/init.py | Introduce package marker/docstring for cv2-facade tests. |
| tests/annotators/test_core.py | Switch test OpenCV import to the _cv2 facade. |
| src/supervision/utils/video.py | Route video utilities’ OpenCV usage through _cv2. |
| src/supervision/utils/notebook.py | Route notebook rendering conversions through _cv2. |
| src/supervision/utils/image.py | Route image utilities’ OpenCV usage through _cv2. |
| src/supervision/utils/conversion.py | Route conversion helpers’ OpenCV usage through _cv2. |
| src/supervision/metrics/detection.py | Update lazy OpenCV import sites to use _cv2. |
| src/supervision/key_points/core.py | Update doc examples to import OpenCV via _cv2. |
| src/supervision/key_points/annotators.py | Route keypoint annotators’ OpenCV usage through _cv2. |
| src/supervision/draw/utils.py | Route drawing helpers’ OpenCV usage through _cv2. |
| src/supervision/detection/utils/polygons.py | Route polygon helpers’ OpenCV usage through _cv2. |
| src/supervision/detection/utils/masks.py | Route mask helpers’ OpenCV usage through _cv2. |
| src/supervision/detection/utils/iou_and_nms.py | Route IoU/NMS helpers’ OpenCV usage through _cv2. |
| src/supervision/detection/utils/internal.py | Route internal detection helpers’ OpenCV usage through _cv2. |
| src/supervision/detection/utils/converters.py | Route converter helpers’ OpenCV usage through _cv2. |
| src/supervision/detection/tools/polygon_zone.py | Route PolygonZone OpenCV usage through _cv2. |
| src/supervision/detection/tools/inference_slicer.py | Update doc examples to import OpenCV via _cv2. |
| src/supervision/detection/line_zone.py | Route LineZone OpenCV usage through _cv2. |
| src/supervision/detection/core.py | Update doc examples to import OpenCV via _cv2. |
| src/supervision/detection/compact_mask.py | Route compact mask resize path through _cv2. |
| src/supervision/dataset/utils.py | Route dataset utilities’ OpenCV usage through _cv2. |
| src/supervision/dataset/formats/pascal_voc.py | Route Pascal VOC format OpenCV usage through _cv2. |
| src/supervision/dataset/core.py | Route dataset core OpenCV usage through _cv2. |
| src/supervision/classification/core.py | Update doc examples to import OpenCV via _cv2. |
| src/supervision/annotators/core.py | Route annotators’ OpenCV usage (and examples) through _cv2. |
| src/supervision/_cv2/init.py | New OpenCV facade module with fallback constants + explicit failure for missing backend. |
[resolve group] PR #2430 — item 1 --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: OpenAI Codex <codex@openai.com>
[resolve group] PR #2430 — items 2 3 --- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: OpenAI Codex <codex@openai.com>
--- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Codex <codex@openai.com>
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.
This pull request introduces a new private OpenCV compatibility layer (
src/supervision/_cv2/__init__.py) and refactors the codebase to use it. The main goal is to centralize OpenCV imports and provide a fallback mechanism when OpenCV is not installed, improving robustness and portability. All directcv2imports throughout the codebase are replaced with imports from this new compatibility module.Key changes:
OpenCV Compatibility Layer
src/supervision/_cv2/__init__.pythat acts as a compatibility layer for OpenCV. It exposes OpenCV constants and functions ifcv2is available, and provides clear error messages or fallbacks if not.Refactoring Imports
import cv2statements withfrom supervision import _cv2 as cv2throughout the codebase, including in docstring examples, to ensure consistent usage of the compatibility layer. [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]Consistency in Examples
These changes make the codebase more robust to environments where OpenCV may not be installed and simplify future maintenance by centralizing OpenCV-related logic.