Skip to content

feat(cv2): add drawing fallbacks - #2433

Merged
Borda merged 3 commits into
developfrom
cv2/4
Jul 16, 2026
Merged

Borda merged 3 commits into
developfrom
cv2/4

Conversation

@Borda

@Borda Borda commented Jul 16, 2026

Copy link
Copy Markdown
Member

This pull request introduces comprehensive Pillow-based fallback implementations for several OpenCV drawing functions in the supervision._cv2 module. These fallbacks allow drawing operations such as lines, rectangles, circles, ellipses, polygons, and contours to work even when OpenCV is not available, ensuring broader compatibility and robustness. The PR also adds extensive tests to verify the correctness and compatibility of these fallbacks with OpenCV's behavior.

New Pillow-based drawing fallbacks:

  • Added _circle, _draw_contours, _ellipse, _fill_poly, _line, _polylines, and _rectangle implementations in src/supervision/_cv2/_drawing.py, providing in-place drawing operations using Pillow that closely mimic OpenCV's API and conventions.

Integration into the OpenCV facade:

  • Updated src/supervision/_cv2/__init__.py to expose the new fallback drawing functions in the module's public API, replacing previous _unavailable stubs. [1] [2] [3]

Testing and validation:

  • Added a new test module tests/cv2/test_drawing.py with comprehensive tests for all new fallback drawing functions, ensuring their correctness and compatibility with OpenCV's reference implementation.
  • Enhanced tests/cv2/test_constants.py to verify that the OpenCV facade correctly binds the new fallback drawing operations when OpenCV is not present.

These changes significantly improve the reliability and portability of the drawing utilities in the absence of OpenCV, and ensure their correctness through robust testing.

@codecov

codecov Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.21168% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 86%. Comparing base (7096ee9) to head (8b92fa9).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #2433    +/-   ##
========================================
  Coverage       86%     86%            
========================================
  Files           81      82     +1     
  Lines        11376   11507   +131     
========================================
+ Hits          9837    9951   +114     
- Misses        1539    1556    +17     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends supervision._cv2’s fallback backend with Pillow-based implementations of key OpenCV drawing primitives so Supervision drawing utilities can continue to work when cv2 is unavailable, and adds tests to validate behavior and facade bindings.

Changes:

  • Added Pillow-based in-place drawing fallbacks for line, rectangle, circle, ellipse, polylines, fillPoly, and drawContours.
  • Wired the new drawing fallbacks into the _cv2 facade when OpenCV is not present.
  • Added/extended tests for fallback bindings and drawing behavior (with OpenCV as reference where available).

Review scores (n/5):

  • Code quality: 4/5
  • Testing: 3/5
  • Docs: 4/5

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/supervision/_cv2/_drawing.py Introduces Pillow-based fallback implementations for drawing APIs.
src/supervision/_cv2/__init__.py Exposes the new fallback drawing functions through the _cv2 facade when cv2 is unavailable.
tests/cv2/test_drawing.py Adds reference comparisons against OpenCV and a subprocess consumer test to validate fallback behavior.
tests/cv2/test_constants.py Extends facade binding checks to include the new drawing fallbacks.

Comment thread tests/cv2/test_drawing.py Resolved
Comment thread tests/cv2/test_drawing.py Resolved
Comment thread src/supervision/_cv2/_drawing.py Resolved
Borda and others added 2 commits July 16, 2026 12:04
[resolve group] PR #2433 — items 3

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: OpenAI Codex <[email protected]>
[resolve group] PR #2433 — items 2

---
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
@Borda
Borda merged commit 39eb657 into develop Jul 16, 2026
24 checks passed
@Borda
Borda deleted the cv2/4 branch July 16, 2026 10:53
@Borda Borda mentioned this pull request Jul 29, 2026
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.

2 participants