[A] Add draw_detection func - #25
Merged
Merged
Conversation
kunkunlin1221
approved these changes
Jul 8, 2025
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.
✨ Summary
This PR introduces a new utility
draw_detection()to thecapybara/vision/visualization/draw.pymodule for rendering detection results on images, along with minor cleanups and shared constant reuse.✅ Major Changes
1. New API:
draw_detection()Adds a high-level utility to draw labeled detection boxes (with optional confidence score) onto images.
Features:
Box rendering:
box_alphaLabel rendering:
label 92.3%)Color selection:
Other options:
font_path,text_size,text_color,text_bg_alphaExample usage:
2. Shared Font Path Constant
DEFAULT_FONT_PATHas a shared constant3. Guard for Font Download
Updated logic to correctly check and download the font only if missing:
🧠 Motivation
draw_box()anddraw_text()were too low-level for rendering detection results in a single call.🖼️ Visual Behavior
🧪 Test Coverage
This utility is self-contained and built upon existing well-tested primitives:
prepare_img,prepare_boxcv2.rectangle,ImageFont,ImageDrawOptional follow-up PR can add unit tests using synthetic inputs to assert image output properties.
🔄 API Summary
✅ Checklist
draw_detection()implemented and documented